SodiumSecretBox
struct SodiumSecretBox
A wrapper for symmetric encryption.
-
The initializer is disabled.
Declaration
Swift
fileprivate init() -
The size of the key in bytes.
Declaration
Swift
let sizeOfKeyInBytes: Int -
The size of the nonce in bytes.
Declaration
Swift
let sizeOfNonceInBytes: Int -
The size of the message authentication code (MAC) in bytes.
Declaration
Swift
let sizeOfMacInBytes: Int -
Generates a new symmetric key.
Declaration
Swift
func keygen(_ pointer: UnsafeMutablePointer<UInt8>)Parameters
pointerThe memory region where the key will be stored.
-
Encrypt data.
Declaration
Parameters
plaintextThe text that should be encrypted.
nonceA pointer to the nonce.
keyA pointer to the key.
Return Value
A tuple (MAC, ciphertext).
-
Decrypt data.
Precondition
precondition:
- size of
mac=sizeOfMacInBytes - size of
nonce=sizeOfNonceInBytes - size of
key=sizeOfKeyInBytes
Postcondition
result.count=ciphertext.countDeclaration
Parameters
ciphertextThe ciphertext.
macA pointer to the message authentication code (MAC).
nonceA pointer to the nonce.
keyA pointer to the key.
Return Value
The plaintext,
nilif the integrity of the authenticated ciphertext could not be verified. - size of
View on GitHub
SodiumSecretBox Structure Reference