Browse Questions
- Identifiable requires a type to have a unique id property.
- The three modes differ in where the authentication token lives and whether the output grows: Seal appends the token to the ciphertext, Token Protect returns the token separately so the ciphertext…
- Firebase Cloud Messaging (FCM) lets you send push notifications to your iOS app through Apple Push Notification service (APNs).
- setNeedsLayout schedules a layout pass for later, layoutIfNeeded forces any pending layout to happen immediately, and setNeedsDisplay schedules a redraw of the view's content.
Answer: The three modes differ in where the authentication token lives and whether the output grows: Seal appends the token to the ciphertext, Token Protect returns the token separately so the ciphertext stays the same length as the plaintext, and Context Imprint produces length-preserving output with no token and therefore no integrity check.
| Mode | Output size | Integrity check | Use when |
|---|---|---|---|
| Seal | plaintext + ~44 bytes | Yes | Default — you control the storage |
| Token Protect | exactly plaintext length, plus a separate token | Yes | Fixed-width DB column; token stored in another column |
| Context Imprint | exactly plaintext length | No | Legacy formats with zero room for overhead |
Context Imprint is a last resort. Without a token it cannot detect tampering, and it requires a non-empty context to be secure at all.
Code Example:
// Seal — one blob, simplest
let sealed = try TSCellSeal(key: key)!.encrypt(data)
// Token Protect — ciphertext and token stored separately
let cell = TSCellToken(key: key)!
let result = try cell.encrypt(data, context: context)
store(cipherText: result.cipherText, token: result.token)
let back = try cell.decrypt(result.cipherText, token: result.token, context: context)
// Context Imprint — no integrity guarantee, context is mandatory
let imprint = TSCellContextImprint(key: key)!
let same = try imprint.encrypt(data, context: context) // same length as `data`
Key Points:
- Default to Seal unless a storage constraint forces otherwise.
- Token Protect keeps the ciphertext column width unchanged.
- Context Imprint trades integrity for size — never use it with an empty context.