Skip to content
@deckyard/sealbox

sealbox cheatsheet

Every export of @deckyard/sealbox. Guides are listed in the introduction.

jennifer
import "@deckyard/sealbox/" as sealbox;

Every failure to open is Error{kind: "sealbox"} with the message sealbox: cannot open (wrong key, or the data was changed).

Sealed boxes

FunctionReturnsDoes
sealbox.newKey()bytes32 crypto-grade random bytes
sealbox.seal(plaintext, key)bytesAES-256-GCM under a fresh nonce: nonce || ciphertext || tag
sealbox.open(box, key)bytesThe plaintext of a box seal made
sealbox.sealWith(plaintext, key, aad)bytesseal with associated data
sealbox.openWith(box, key, aad)bytesOpen with the same associated data

Encrypt-then-MAC

FunctionReturnsDoes
sealbox.cbcHmacSeal(plaintext, encKey, macKey)CbcHmacAES-CBC (PKCS#7, random IV) and HMAC-SHA256 over iv || ciphertext
sealbox.cbcHmacOpen(box, encKey, macKey)bytesCheck the MAC in constant time, then decrypt

CbcHmac

FieldMeaning
iv as bytesthe 16-byte CBC IV
ciphertext as bytesAES-CBC with PKCS#7 padding
mac as bytesthe 32-byte HMAC-SHA256 over iv || ciphertext

Fernet

FunctionReturnsDoes
sealbox.fernetEncrypt(plaintext, key)stringA Fernet token; key is 32 bytes in base64url
sealbox.fernetDecrypt(token, key, ttlSeconds)bytesThe plaintext; ttlSeconds 0 accepts any age (a token from the future is still refused); only the canonical base64url spelling is accepted

Constants

ConstantValueMeaning
KEY_BYTES32key length for seal / open
NONCE_BYTES12nonce in front of a sealed box
TAG_BYTES16GCM tag at the end of a sealed box
FERNET_MAX_CLOCK_SKEW60seconds a Fernet timestamp may lie in the future