Encryption
Encrypt values with ENCRYPT() and DECRYPT(), bind them to the client of a request with ENCRYPTREQ() and DECRYPTREQ(), and choose the cipher.
ENCRYPT(value, key) turns any JSON-serializable value into a string and DECRYPT(string, key) turns it back, or returns null for an invalid string. The secret CONF.secret is part of the key.
var token = ENCRYPT({ id: user.id, expire: NOW.add('1 day') }, 'reset');
var data = DECRYPT(token, 'reset');ENCRYPTREQ($, value, key) and DECRYPTREQ($, value, key) bind the value to the browser of the request (a hash of User-Agent, and the IP address with strict), so a token copied to another client does not decrypt:
var token = ENCRYPTREQ($, { id: user.id }, 'download');
// later, in another request of the same browser
var data = DECRYPTREQ($, token, 'download');To use a Node.js cipher instead of the built-in algorithm, set $crypto in the configuration (for example aes-256-cbc). The key then must have the byte length the cipher needs.