Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cryp

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cryp

encrypt and decrypt data, sign and verify data

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Cryp.js

Usage

var Cryp = require('cryp');
var crypto = require('crypto');

// create a cryp object
var cryp = new Cryp([crypto.pbkdf2Sync('pASsWoRD', 'SaLt', 4096, 32)]);

// encrypt
// cryp.encrypt(data, outputEncoding)
// data: utf-8 string or buffer
// if outputEncoding is undefined, return buffer. Otherwise return string encoded using outputEncoding
var data = cryp.encrypt('hello', 'base64');

// decrypt
// cryp.decrypt(data, [inputEncoding], outputEncoding)
// inputEncoding: the encoding of data. If data is a Buffer then dataEncoding is ignored.
// if outputEncoding is undefined, return buffer. Otherwise return string encoded using outputEncoding
cryp.decrypt(data, 'base64', 'utf8') == 'hello';

var data = cryp.encrypt('hello');
cryp.decrypt(data, 'utf8') == 'hello';
cryp.decrypt(data).toString() == 'hello';


// tamper the data
var data = cryp.encrypt('hello', 'base64');
data = 'a' + data;
// return null
cryp.decrypt(data, 'base64', 'utf8') == null;


// using rotate keys
var data = cryp.encrypt('hello', 'base64');
var cryp2 = new Cryp([
  crypto.pbkdf2Sync('NEWpASsWoRD', 'SaLt', 4096, 32),
  crypto.pbkdf2Sync('pASsWoRD', 'SaLt', 4096, 32)
]);
cryp2.decrypt(data, 'base64', 'utf8') == 'hello';

// sign data
// cryp.sign(data)
// data: buffer or utf-8 string
// return: signed string
var data = cryp.sign('hello');
cryp.unsign(data) == 'hello';

// tamper the signed data
var data = cryp.sign('hello');
data = 'a' + data;
// return null
cryp.unsign(data) == null;

// using rotate keys
var data = cryp.sign('hello');
var cryp2 = new Cryp([
  crypto.pbkdf2Sync('NEWpASsWoRD', 'SaLt', 4096, 32),
  crypto.pbkdf2Sync('pASsWoRD', 'SaLt', 4096, 32)
]);
cryp2.unsign(data) == 'hello';

License

MIT

Keywords

FAQs

Package last updated on 19 May 2015

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