New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cookie-encrypter

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cookie-encrypter

cookie encryption

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
784
decreased by-78.46%
Maintainers
1
Weekly downloads
 
Created
Source

Express middleware to use with cookie-parser. Transparently encrypt and decrypt cookies with req.cookies (populated by cookie-parser). Support all cookies (including http-only and signed) with string content or JSON. Use aes256 as the default encryption algorithm.

Installation

$ npm install cookie-encrypter

API

var express = require('express');
var cookieParser = require('cookie-parser');
var cookieEncrypter = require('cookie-encrypter');
var secretKey = 'foobarbaz12345';

var app = express();
app.use(cookieParser(secretKey));
app.use(cookieEncrypter(secretKey));

cookieEncrypter(secret, options)

  • secret a string or array used for encrypting cookies.
  • options an optional object to set options for encryption.
  • options.algorithm algorithm used to encrypt cookie data (any algorithm supported by OpenSSL). aes256 used as the default one.

cookieEncrypter.encryptCookie(str, options)

Encrypt a cookie value and return it. An options.algorithm can optionaly be passed to specify an algorithm to use for the encryption.

cookieEncrypter.decryptCookie(str, options)

Decrypt a cookie value and return it. An options.algorithm can optionaly be passed to specify an algorithm to use for the decryption.

Example

var express = require('express');
var cookieParser = require('cookie-parser');
var cookieEncrypter = require('cookie-encrypter');
var secretKey = 'foobarbaz12345';

var app = express();
app.use(cookieParser(secretKey));
app.use(cookieEncrypter(secretKey));

app.get('/setcookies', function(req, res) {
  const cookieParams = {
    httpOnly: true,
    signed: true,
    maxAge: 300000,
  };

  res.cookie('supercookie', 'my data is encrypted', cookieParams);
  // OR ALTERNATIVELY
  // res.cookie('supercookie', { myData: 'is encrypted' }, cookieParams);
  
  res.end('new cookie set (supercookie)');
})

app.get('/getcookies', function(req, res) {
  console.log('Decrypted cookies: ', req.signedCookies)
});

app.listen(8080);

Keywords

FAQs

Package last updated on 29 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc