cookie-signature
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Cookie-signature is a powerful npm package primarily designed to secure cookies by signing and unsigning them. It boosts the security of cookie-based applications by preventing tampering and making your cookies more secure.
Using cookie-signature is quite simple and straightforward. Firstly, you need to install the package into your project using npm - npm install cookie-signature
. Then, you can require the package and use its sign and unsign methods as shown in the example below:
var cookie = require('cookie-signature');
// signing a cookie
var val = cookie.sign('hello', 'tobiiscool');
console.log(val); // outputs: hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI
// unsigning a cookie
var origValue = cookie.unsign(val, 'tobiiscool');
console.log(origValue); // outputs: hello
// unsigning a cookie with wrong secret returns false
var wrongValue = cookie.unsign(val, 'luna');
console.log(wrongValue); // outputs: false
In the above code, 'hello' is the value of the cookie and 'tobiiscool' is the secret with which the cookie is signed or unsigned.
Unfortunately, there is no separate documentation provided for cookie-signature. Most of the vital information you need to use the package can be found in the readme of the package's GitHub repository. You can view various usage examples and explanations directly on the GitHub repo.