crypto-cookie
Usage
var cryptoCookie = require('crypto-cookie');
var cookie = new CryptoCookie(req, res);
cookie.set('sessionId', 123);
cookie.get('sessionId');
cookie.reqCookies.sessionId
cookie.set('attrs', 'ok', {
maxAge: 500,
expires: new Date('2015-05-13T07:30:00Z'),
path: '/foo',
domain: 'www.example.com',
secure: true,
httpOnly: true
});
cookie.remove('foo');
cookie.remove('foo', {
path: '/foo',
domain: 'www.example.com'
});
cookie.set('expiresGMT', 'ok', {
expires: 'Wed, 13 May 2015 07:30:00 GMT'
});
cookie.set('expiresISODate', 'ok', {
expires: '2015-05-13T07:30:00Z'
});
cookie.set('expiresLocalDate', 'ok', {
expires: '2015-05-13 07:30:00'
});
cookie.set('expiresTimestamp', 'ok', {
expires: 1431922243259
});
var cookie = new CryptoCookie(req, res, {
maxAge: 500,
expires: new Date('2015-05-13T07:30:00Z'),
path: '/foo',
domain: 'www.example.com',
secure: true,
httpOnly: true
});
cookie.set('defaults', 'ok', {
maxAge: 1000
});
var cookie = new CryptoCookie(req, res, {
keys: [crypto.pbkdf2Sync('pASsWoRD', 'SaLt', 4096, 32)]
});
cookie.set('encrypted', 'ok', {
encrypted: true
});
var value = cookie.get('encrypted', {
encrypted: true
});
cookie.set('signed', 'ok', {
signed: true
});
var value = cookie.get('signed', {
signed: true
});
var cookie = new CryptoCookie(req, res, {
keys: [
crypto.pbkdf2Sync('NEWpASsWoRD', 'SaLt', 4096, 32),
crypto.pbkdf2Sync('pASsWoRD', 'SaLt', 4096, 32)
]
});
var encrypted = cookie.get('encrypted', {
encrypted: true
});
var signed = cookie.get('signed', {
signed: true
});
License
MIT