INNER CODE UNIT · Swift
seal
jedisct1/swift-sodium · Sources/Sodium/Box.swift:183
func seal(message: Bytes, beforenm: Beforenm) -> (authenticatedCipherText: Bytes, nonce: Nonce)? {
guard beforenm.count == BeforenmBytes else { return nil }
var authenticatedCipherText = Bytes(count: message.count + MacBytes)
let nonce = nonce()
guard crypto_box_easy_afternm(
&authenticatedCipherText,
message, UInt64(message.count),
nonce,
beforenm
).exitCode == .SUCCESS else { return nil }
return (authenticatedCipherText: authenticatedCipherText, nonce: nonce)
}
/**
Encrypts a message with the shared secret key generated from a recipient's public key and a sender's secret key using `beforenm()`.