SecuritySeniorMCQ

What is the difference between Secure Cell's Seal, Token Protect, and Context Imprint modes?

Test your knowledge:

Explanation & Code

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.

ModeOutput sizeIntegrity checkUse when
Sealplaintext + ~44 bytesYesDefault — you control the storage
Token Protectexactly plaintext length, plus a separate tokenYesFixed-width DB column; token stored in another column
Context Imprintexactly plaintext lengthNoLegacy 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.

Rate your understanding:

Ready to practice more Security?

Test yourself with our interactive quiz mode or browse all curated questions for this topic.