Skip to content
Not available in DartThis function is not part of the Dart package. The documentation below is for JavaScript and Python.

decrypt

Requires a Node.js runtime ('qsu/node')

Decrypt with the specified algorithm (default: aes-256-cbc) using a string and a secret (secret).

str must be a string produced by encrypt: iv:encrypted, or iv:authTag:encrypted for AEAD algorithms (gcm, ccm, ocb, poly1305). The algorithm and toBase64 values must match the ones used to encrypt. An input in any other shape throws.

Decryption also throws when the key is wrong or the ciphertext has been altered, so wrap the call in try/catch when the input is not under your control.

Parameters

NameTypeRequiredDefault
strstringstr
The string returned by encrypt. An empty string returns an empty string.
secretstringstr
The same key that was used to encrypt.
algorithmstringstr'aes-256-cbc'
toBase64booleanboolfalseFalse

Returns

string

str

Examples

javascript
const secret = '12345678901234567890123456789012'; // 32 bytes

decrypt('61ba43b65fc...', secret);
decrypt(encrypt('test', secret, 'aes-256-gcm', 12), secret, 'aes-256-gcm'); // 'test'
python
secret = '12345678901234567890123456789012'  # 32 bytes

decrypt('61ba43b65fc...', secret)

Released under the MIT License