Cifratura
Cifra i valori con ENCRYPT() e DECRYPT(), legali al client di una richiesta con ENCRYPTREQ() e DECRYPTREQ() e scegli il cifrario.
ENCRYPT(value, key) trasforma qualsiasi valore serializzabile in JSON in una stringa e DECRYPT(string, key) lo riconverte, o restituisce null per una stringa non valida. Il segreto CONF.secret fa parte della chiave.
var token = ENCRYPT({ id: user.id, expire: NOW.add('1 day') }, 'reset');
var data = DECRYPT(token, 'reset');ENCRYPTREQ($, value, key) e DECRYPTREQ($, value, key) legano il valore al browser della richiesta (un hash di User-Agent, e dell'indirizzo IP con strict), così un token copiato su un altro client non viene decifrato:
var token = ENCRYPTREQ($, { id: user.id }, 'download');
// later, in another request of the same browser
var data = DECRYPTREQ($, token, 'download');Per usare un cifrario di Node.js invece dell'algoritmo integrato, imposta $crypto nella configurazione (per esempio aes-256-cbc). La chiave deve allora avere la lunghezza in byte richiesta dal cifrario.