INNER CODE UNIT · Swift
seal
jedisct1/swift-sodium · Sources/Sodium/Box.swift:78
func seal(message: Bytes, recipientPublicKey: PublicKey, senderSecretKey: SecretKey, nonce: Nonce) -> Bytes? {
guard recipientPublicKey.count == PublicKeyBytes,
senderSecretKey.count == SecretKeyBytes,
nonce.count == NonceBytes
else { return nil }
var authenticatedCipherText = Bytes(count: message.count + MacBytes)
guard crypto_box_easy(
&authenticatedCipherText,
message,
CUnsignedLongLong(message.count),
nonce,
recipientPublicKey,
senderSecretKey
).exitCode == .SUCCESS else { return nil }
return authenticatedCipherText