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

krypt

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

krypt - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

6

CHANGELOG.md

@@ -17,1 +17,7 @@ ## 0.1.0 (3/7/2014)

+ Fixed typo in payload
## 0.3.0 (3/18/2014)
+ Updated `keyLength` to be expressed in bits (w/ legacy support for converting 32 Byte length keys)
+ Added support to inject custom context into the encrypted result
+ Useful for recording metadata, such as the name of the key you are using, etc.

32

lib/krypt.js

@@ -8,7 +8,8 @@ /*!

var crypto = require('crypto');
var crypto = require('crypto'),
_ = require('lodash');
var CIPHER = 'aes-256-cbc',
KEY_DERIVATION = 'pbkdf2',
DEFAULT_KEY_LENGTH = 32,
DEFAULT_KEY_LENGTH = 256,
DEFAULT_ITERATIONS = 64000;

@@ -31,2 +32,3 @@

this.defaultSecret = config.secret;
this.context = config.context || {};
}

@@ -48,3 +50,7 @@

Krypt.prototype.setContext = function setContext(context) {
this.context = context;
};
Krypt.prototype.encrypt = function encrypt(input, secret) {

@@ -61,3 +67,8 @@

var salt = crypto.randomBytes(this.keyLength),
// Legacy check to deal with old versions that recorded key length in Bytes
if (this.keyLength === 32) {
this.keyLength = this.keyLength * 8;
}
var salt = crypto.randomBytes(this.keyLength / 8),
iv = crypto.randomBytes(16);

@@ -67,3 +78,3 @@

var key = crypto.pbkdf2Sync(secret, salt, this.iterations, this.keyLength),
var key = crypto.pbkdf2Sync(secret, salt, this.iterations, this.keyLength / 8),
cipher = crypto.createCipheriv(CIPHER, key, iv);

@@ -74,3 +85,3 @@

return {
var result = {
cipher: CIPHER,

@@ -85,2 +96,6 @@ keyDerivation: KEY_DERIVATION,

_.defaults(result, this.context);
return result;
} catch (err) {

@@ -125,5 +140,10 @@ throw new Error('Unable to encrypt value due to: ' + err);

// Legacy check to deal with old versions that recorded key length in Bytes
if (keyLength === 32) {
keyLength = keyLength * 8;
}
try {
var key = crypto.pbkdf2Sync(secret, salt, iterations, keyLength),
var key = crypto.pbkdf2Sync(secret, salt, iterations, keyLength / 8),
decipher = crypto.createDecipheriv(CIPHER, key, iv);

@@ -130,0 +150,0 @@

5

package.json
{
"name": "krypt",
"version": "0.2.2",
"version": "0.3.0",
"description": "Simple, secure symmetric encryption utility for Node.",

@@ -26,3 +26,4 @@ "main": "index.js",

"dependencies": {
"nconf": "~0.6.9"
"nconf": "~0.6.9",
"lodash": "~2.4.1"
},

@@ -29,0 +30,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

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