Skip to Content
oxcrypto

crypto_secretbox

Secret-key authenticated encryption compatible with libsodium crypto_secretbox.

from oxcrypto.nacl.crypto_secretbox import CRYPTO_SECRETBOX
from oxcrypto.random import bytes as random_bytes

box = CRYPTO_SECRETBOX.XSALSA20POLY1305
key, nonce = random_bytes(32), random_bytes(24)
ciphertext = box.encrypt(key, nonce, b"hello")
assert box.decrypt(key, nonce, ciphertext) == b"hello"
Variantlibsodium nameKeyNonce
XSALSA20POLY1305crypto_secretbox_xsalsa20poly130532 bytes24 bytes
XCHACHA20POLY1305crypto_secretbox_xchacha20poly130532 bytes24 bytes

The output is the 16-byte tag followed by the ciphertext, as in crypto_secretbox_easy. Associated data is not supported by this construction.

PropertyValue
StandardNaCl and libsodium construction; not an IETF or NIST standard
Cratecrypto_secretbox 0.1.1, stable, no published audit
MSRVRust 1.60 declared; builds with Rust 1.88
Test vectorscrypto_secretbox 0.1.1 tests/lib.rs: NaCl tests/secretbox.c for XSalsa20-Poly1305, libsodium-generated for XChaCha20-Poly1305