AEAD (Authenticated Encryption with Additional Data)
Bindings for the crypto_aead_* APIs. See the libsodium AEAD docs for more information.
Currently, only crypto_aead_xchacha20poly1305_ietf is exposed.
Constants
Buffer lengths (integer)
crypto_aead_xchacha20poly1305_ietf_ABYTEScrypto_aead_xchacha20poly1305_ietf_KEYBYTEScrypto_aead_xchacha20poly1305_ietf_NPUBBYTEScrypto_aead_xchacha20poly1305_ietf_NSECBYTEScrypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX- Note this isNumber.MAX_SAFE_INTEGERfor now
crypto_aead_xchacha20poly1305_ietf_keygen
sodium.crypto_aead_xchacha20poly1305_ietf_keygen(k)
Generates a new encryption k.
kshould be abufferof lengthcrypto_aead_xchacha20poly1305_ietf_KEYBYTES.
The generated key is stored in k.
crypto_aead_xchacha20poly1305_ietf_encrypt
var clen = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(c, m, [ad], null, npub, k)
Encrypts a message with (npub, k) and optional additional data ad.
cshould be abufferof sizem.length + crypto_aead_xchacha20poly1305_ietf_ABYTESmshould be abufferadis optional and should benullor abuffer. Included in the computation of authentication tag appended to the mnullis in the position of the unusednsecargument. This should always benullnpubshould be abufferof lengthcrypto_aead_xchacha20poly1305_ietf_NPUBBYTESkshould be abufferof lengthcrypto_aead_xchacha20poly1305_ietf_KEYBYTES
Returns how many bytes were written to c. Note that in-place encryption is possible.
crypto_aead_xchacha20poly1305_ietf_decrypt
var mlen = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(m, null, c, [ad], npub, k)
Decrypts a message with (npub, k) and optional additional data ad.
mshould be abufferof sizec.length - crypto_aead_xchacha20poly1305_ietf_ABYTESnullis in the position of the unusednsecargument. This should always benullcshould be abufferadis optional and should benullor abuffer. Included in the computation of authentication tag appended to the mnpubshould be abufferof lengthcrypto_aead_xchacha20poly1305_ietf_NPUBBYTESkshould be abufferof lengthcrypto_aead_xchacha20poly1305_ietf_KEYBYTES
Returns how many bytes were written to message. Note that in-place encryption is possible.
crypto_aead_xchacha20poly1305_ietf_encrypt_detached
var maclen = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt_detached(c, mac, m, [ad], null, npub, k)
Encrypts a message with (npub, k) and optional additional data ad.
cshould be abufferof sizem.lengthmacshould be abufferof sizecrypto_aead_xchacha20poly1305_ietf_ABYTESmshould be abufferadis optional and should benullor abuffer. Included in the computation of authentication tag appended to the mnullis in the position of the unusednsecargument. This should always benullnpubshould be abufferof lengthcrypto_aead_xchacha20poly1305_ietf_NPUBBYTESkshould be abufferof lengthcrypto_aead_xchacha20poly1305_ietf_KEYBYTES
Returns how many bytes were written to mac. Note that in-place encryption is possible.
crypto_aead_xchacha20poly1305_ietf_decrypt_detached
sodium.crypto_aead_xchacha20poly1305_ietf_decrypt_detached(m, null, c, mac, [ad], npub, k)
Decrypts a message with (npub, k) and optional additional data ad.
mshould be abufferof sizec.lengthnullis in the position of the unusednsecargument. This should always benullcshould be abuffermacshould be abufferof sizecrypto_aead_xchacha20poly1305_ietf_ABYTESadis optional and should benullor abuffer. Included in the computation of authentication tag appended to the mnpubshould be abufferof lengthcrypto_aead_xchacha20poly1305_ietf_NPUBBYTESkshould be abufferof lengthcrypto_aead_xchacha20poly1305_ietf_KEYBYTES
Returns nothing, but will throw on in case the MAC cannot be authenticated. Note that in-place encryption is possible.
