What is cookie-signature?
The cookie-signature package is used to sign and unsign values using a secret key, typically for use in cookie values to prevent tampering. It provides a simple API for signing and verifying strings.
What are cookie-signature's main functionalities?
Sign
This feature allows you to sign a value using a secret key. The result is a signed value that can be used in a cookie or other transport method. The signature is appended to the value with a 's:' prefix.
"signature = require('cookie-signature');\nsignedValue = signature.sign('value', 'secret');"
Unsign
This feature allows you to unsign a previously signed value using the same secret key. If the signature is valid, the original value is returned. If the signature is invalid, a false value is returned, indicating potential tampering.
"signature = require('cookie-signature');\nunsignedValue = signature.unsign('signedValue', 'secret');"
Other packages similar to cookie-signature
jsonwebtoken
jsonwebtoken (or JWT) is a package that allows you to encode and decode JSON Web Tokens, which are an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This package provides more complex features like token expiration, audience, issuer validation, and more, compared to the simpler cookie-signature package.
secure-cookie
secure-cookie is a package that provides cookie signing and encryption. It offers additional security by encrypting the cookie value, which cookie-signature does not do. secure-cookie is a good choice if you need to protect sensitive information in cookies beyond just preventing tampering.
keygrip
keygrip is a package for signing and verifying data (like cookies) but with support for key rotation. It allows you to use an array of keys for signing and will verify signatures against any of the provided keys. This is useful for applications that need to rotate secrets without invalidating existing signatures, which is not a feature provided by cookie-signature.
cookie-signature
Sign and unsign cookies.
Example
var cookie = require('cookie-signature');
var val = cookie.sign('hello', 'tobiiscool');
val.should.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI');
var val = cookie.sign('hello', 'tobiiscool');
cookie.unsign(val, 'tobiiscool').should.equal('hello');
cookie.unsign(val, 'luna').should.be.false;
License
(The MIT License)
Copyright (c) 2012 LearnBoost <tj@learnboost.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.