chloride.secretbox

Undocumented in source.

Members

Aliases

Nonce
alias Nonce = ubyte[crypto_secretbox_NONCEBYTES]
Undocumented in source.
SecretKey
alias SecretKey = ubyte[crypto_secretbox_KEYBYTES]
Undocumented in source.
SecretMacLength
alias SecretMacLength = crypto_secretbox_MACBYTES
Undocumented in source.
makeNonce
alias makeNonce = randomArray!Nonce

Generate a nonce suitable for secret key encryption.

makeSecretKey
alias makeSecretKey = randomArray!SecretKey

Generate a key suitable for secret key encryption.

Functions

decryptSecretBox
ubyte[] decryptSecretBox(ubyte[] cipher, Nonce nonce, SecretKey key)

Wrapper around crypto_secretbox_open_easy. Decrypts a cipher using a nonce and key and returns the decrypted message. If decryption fails, null is returned.

decryptSecretBoxInPlace
bool decryptSecretBoxInPlace(ubyte[] buffer, Nonce nonce, SecretKey key)

Wrapper around crypto_secretbox_open_easy that decrypts in place. buffer is changed in place from the cipher to the decrypted message. If decryption is successful, true is returned and buffer is updated with the length of the decrypted message, which will be shorter than the cipher. Otherwise true will be returned.

encryptSecretBox
ubyte[] encryptSecretBox(ubyte[] message, Nonce nonce, SecretKey key)

Wrapper around crypto_secretbox_easy. Encrypts a message using a nonce and key and returns the cipher with MAC as a prefix.

encryptSecretBoxInPlace
void encryptSecretBoxInPlace(ubyte[] buffer, Nonce nonce, SecretKey key)

Wrapper around crypto_secretbox_easy that encrypts in place. buffer is changed in place from the message to the cipher. Note that it will be reallocated to be large enough to include the MAC, which may cause the array to be copied.

openSecretBox
ubyte[] openSecretBox(SecretBox box, SecretKey key)

Decrypt box which contains the ciphertext and the nonce used to generate it. If decryption fails it returns null.

secretBox
SecretBox secretBox(ubyte[] message, SecretKey key)

Encrypt message using key and a newly generated nonce. Return a SecreBox with the encrypted ciphertext and the generated nonce.

Structs

SecretBox
struct SecretBox

A struct containing both the encrypted cipher (using secret key encryption) and the nonce used to encrypt it.

Meta