Javascript port of the Python itsdangerous module with influence from the ReallyDangerous javascript module
- Timestamp Signer
- URL Safe Signer
- Timestamp URL Safe Signer
const itsdanger = require('itsdangerjs');
const signer = itsdanger.Signer('my-secret')
console.log(signer.sign('test'))
// 'test.XxfCnMKrwrLCgGzDnlXCjcKgw4vCjh8ow7oAfMOALxxAwoHCrnrCtcOswojCuVYBwp0DX8KlcW7ClMO7wpUeTWTDu8OOwofDhMO3wpgaQzpSw4Ukw6vCv8OoXl7Dig7DksKp'
console.log(signer.unsign('test.XxfCnMKrwrLCgGzDnlXCjcKgw4vCjh8ow7oAfMOALxxAwoHCrnrCtcOswojCuVYBwp0DX8KlcW7ClMO7wpUeTWTDu8OOwofDhMO3wpgaQzpSw4Ukw6vCv8OoXl7Dig7DksKp'))
// 'test'
secretKey
{String} Secret to be usedsalt
{String} (default is 'itsdangerjs.Signer')sep
{String} (default is '.')digestMethod
{String} Digest method for signing (default is 'sha512')algorithm
{Function|Class} Algorithm to use for hashing (default is HMAC) - see signer.js for details
value
{String} The value to be signed
Returns signed string
signedValue
{String} Signed value
Returns original value if signature is correct
const itsdanger = require('itsdangerjs');
const signer = new itsdanger.TimestampSigner('my-secret');
console.log(signer.sign('test'));
// 'test.AWmhAxll.MGV2wprCk2FkDgfCpsK8w6AZwoAAHwtYwofCjMKrwqwQSAAWOMKYZsKPw5tjFgbCg8KrOcOJwotgY3grW34lecKiaDvCkMOYNxfDuS9CZi8Mw4ksKMKH'
console.log(signer.unsign('test.AWmhAxll.MGV2wprCk2FkDgfCpsK8w6AZwoAAHwtYwofCjMKrwqwQSAAWOMKYZsKPw5tjFgbCg8KrOcOJwotgY3grW34lecKiaDvCkMOYNxfDuS9CZi8Mw4ksKMKH'));
// 'test'
console.log(signer.getTimestamp('test.AWmhAxll.MGV2wprCk2FkDgfCpsK8w6AZwoAAHwtYwofCjMKrwqwQSAAWOMKYZsKPw5tjFgbCg8KrOcOJwotgY3grW34lecKiaDvCkMOYNxfDuS9CZi8Mw4ksKMKH'));
// 1553184596753
secretKey
{String} Secret to be usedsalt
{String} (default is 'itsdangerjs.Signer')sep
{String} (default is '.')digestMethod
{String} Digest method for signing (default is 'sha512')algorithm
{Function|Class} Algorithm to use for hashing (default is HMAC) - see signer.js for details
value
{String} The value to be signed
Returns signed string with timestamp
signedValue
{String} Signed valuemaxAge
{Number} Max age time in millisecondsreturnTimestamp
{Boolean} Return the timestamp used at creation (default is false)
Returns original value if signature is correct and age is less than maxAge (if defined)
const itsdanger = require('itsdangerjs');
const serializer = new itsdanger.URLSafeSerializer('my-secret');
console.log(serializer.dumps('test'));
// 'dGVzdA.TsKHw5E3w4fDh8O1w7PCv8Oxw4pYUDfDpcKfw5vDqABsMMK1EsOsw6MFWcOUwrbClcKYPCl7D1cNeTRtw48mwrDDuzzCuwvDkzIJHcKlC8OgJsK_H8OOw4bCoMOawofDvTU'
console.log(serializer.loads('dGVzdA.TsKHw5E3w4fDh8O1w7PCv8Oxw4pYUDfDpcKfw5vDqABsMMK1EsOsw6MFWcOUwrbClcKYPCl7D1cNeTRtw48mwrDDuzzCuwvDkzIJHcKlC8OgJsK_H8OOw4bCoMOawofDvTU'));
// 'test'
secretKey
{String} Secret to be usedsalt
{String} (default is 'itsdangerjs')serializer
{Function|Class} A function or class that exposes bothloads
anddumps
methods(default isitsdanger.json.Json
) - see json.js for detailssigner
{Function|Class} A fuction or class that will be used to sign values (default isitsdanger.Signer
) - see signer.js for details
obj
{String|Object} The value to be signed and serializedsalt
{String} (default is inherited from the constructor)
Returns signed and serialized object
s
{String} Signed and Serialized value to unsign and deserializersalt
{String} (default is inherited from the constructor)
Returns original object if signature is correct
const itsdanger = require('itsdangerjs');
const serializer = new itsdanger.URLSafeTimedSerializer('my-secret');
console.log(serializer.dumps('test'));
// 'dGVzdA.AWmhGTQv.w6MERcO6CDvCqcKBwr0eMMKGNF7Ci8OPwpVVwpPCisKdw7ZKacOZGcORH8OLw7xzMMOwwrJdLcOhTRpnw7PDv2DDtMOSwpVUCDdbH8OqwqfDozDDh8KXPTTCvGFlwop1'
console.log(serializer.loads('dGVzdA.AWmhGTQv.w6MERcO6CDvCqcKBwr0eMMKGNF7Ci8OPwpVVwpPCisKdw7ZKacOZGcORH8OLw7xzMMOwwrJdLcOhTRpnw7PDv2DDtMOSwpVUCDdbH8OqwqfDozDDh8KXPTTCvGFlwop1'));
// 'test'
console.log(serializer.loads('dGVzdA.AWmhGTQv.w6MERcO6CDvCqcKBwr0eMMKGNF7Ci8OPwpVVwpPCisKdw7ZKacOZGcORH8OLw7xzMMOwwrJdLcOhTRpnw7PDv2DDtMOSwpVUCDdbH8OqwqfDozDDh8KXPTTCvGFlwop1', null, true)
[ 'test', 2019-04-05T15:56:57.391Z ])
secretKey
{String} Secret to be usedsalt
{String} (default is 'itsdangerjs')serializer
{Function|Class} A function or class that exposes bothloads
anddumps
methods(default isitsdanger.json.Json
) - see json.js for detailssigner
{Function|Class} A fuction or class that will be used to sign values (default isitsdanger.TimestampSigner
) - see timed.js for details
obj
{String|Object} The value to be signed and serializedsalt
{String} (default is inherited from the constructor)
Returns signed and serialized object
s
{String} Signed and Serialized value to unsign and deserializermaxAge
{Number} Max age time in millisecondsreturnTimestamp
{Boolean} Return the timestamp used at creation (default is false)salt
{String} (default is inherited from the constructor)
Returns original object if signature is correct