Cryptography
Encrypt data, compute digests and authentication codes, and generate keys or random bytes. Check each function’s input format: some values use Base64 while others are raw bytes.
Functions
crypt.decryptRead ciphertext created by crypt.encrypt. Use the original key, returned IV, and matching AES mode; a new key or mismatched mode cannot recover a previous message.
crypt.encryptEncrypt a byte string with AES and return the ciphertext together with the IV needed to read it later. GCM is a useful choice when you also want tampering with the saved value to be detected.
crypt.generatebytesMake random bytes and receive them as printable Base64. This is handy for a random token that must travel through a text field without an extra encoding step.
crypt.generatekeyGenerate a fresh AES key in the exact format crypt.encrypt expects. Keep this value if you need to decrypt the resulting ciphertext after the script ends.
crypt.hashCalculate a digest of bytes so you can compare a file or payload with a known fingerprint. For authentication between two parties, use crypt.hmac instead because an unkeyed digest can be recomputed by anyone.
crypt.hmacAuthenticate a message with a shared secret. A matching HMAC shows that the same key and message bytes were used, which makes it suitable for checking stored or exchanged data.
crypt.randomRequest random bytes directly when an API expects binary key material, a nonce, or another byte string. Encode them separately if they must be printed or placed in JSON.