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.

    Precondition

    precondition:

    Postcondition

    postcondition:

    Declaration

    Swift

    func encrypt(plaintext: Bytes, nonce: UnsafePointer<UInt8>, key: UnsafePointer<UInt8>) -> (Bytes, Bytes)

    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:

    Postcondition

    result.count = ciphertext.count

    Declaration

    Swift

    func decrypt(ciphertext: Bytes, mac: UnsafePointer<UInt8>, nonce: UnsafePointer<UInt8>, key: UnsafePointer<UInt8>) -> Bytes?

    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.