Browse Questions
- An Optional is a type that can hold either a value or nil.
- Encrypt mode makes the payload unreadable to anyone but the named peer and also proves its origin, while sign/verify mode leaves the payload in the clear and only proves who produced it and that…
- LLDB is the debugger built into Xcode.
- some declares an opaque return type — the function returns a specific concrete type that conforms to a protocol, but the caller doesn't need to know which type it is.
Answer: Encrypt mode makes the payload unreadable to anyone but the named peer and also proves its origin, while sign/verify mode leaves the payload in the clear and only proves who produced it and that it was not modified. Encrypt mode needs both key pairs; sign mode needs only the signer's private key.
Choose sign mode when something between the client and the recipient legitimately needs to read the body — an API gateway routing on a field, a log pipeline, a load balancer. Choose encrypt mode when nothing in the middle should see the contents.
Code Example:
// Encrypt: confidential + authentic. Requires the peer's public key.
let crypter = TSMessage(inEncryptModeWithPrivateKey: myPrivate, peerPublicKey: peerPublic)!
// Sign: authentic only. Body remains readable to any observer.
let signer = TSMessage(inSignVerifyModeWithPrivateKey: myPrivate, peerPublicKey: nil)!
// Verify on the other side with the signer's public key and no private key.
let verifier = TSMessage(inSignVerifyModeWithPrivateKey: nil, peerPublicKey: signerPublic)!
let original = try verifier.unwrapData(signedBlob)
Key Points:
- Signing is not encryption — a signed payload is fully readable in transit.
- Encrypt mode fails if the peer public key does not match the private key's algorithm.
- Verification failure throws; never treat a thrown error as "probably fine".