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
pointer
The memory region where the key will be stored.
-
Encrypt data.
Declaration
Parameters
plaintext
The text that should be encrypted.
nonce
A pointer to the nonce.
key
A 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.count
Declaration
Parameters
ciphertext
The ciphertext.
mac
A pointer to the message authentication code (MAC).
nonce
A pointer to the nonce.
key
A pointer to the key.
Return Value
The plaintext,
nil
if the integrity of the authenticated ciphertext could not be verified. - size of