Comparing version 0.1.0 to 0.2.0
## 0.1.0 (3/7/2014) | ||
+ Initial release | ||
## 0.2.0 (3/7/2014) | ||
+ Updated defaults for key lenght / stretching iterations | ||
+ Enhanced the output to be portable across future versions of Krypt |
39
index.js
@@ -23,6 +23,43 @@ #!/usr/bin/env node | ||
// Load command line options | ||
nconf.argv(); | ||
nconf | ||
.argv({ | ||
'encrypt': { | ||
short: 'e', | ||
describe: 'Path of file to encrypt' | ||
}, | ||
'decrypt': { | ||
short: 'd', | ||
describe: 'Path of file to decrypt' | ||
}, | ||
'secret': { | ||
short: 's', | ||
describe: 'Secret used to encrypt/decrypt file', | ||
demand: true | ||
}, | ||
'iterations': { | ||
short: 'i', | ||
describe: 'Iterations to use for key stretching', | ||
default: 64000 | ||
}, | ||
'length': { | ||
short: 'l', | ||
describe: 'Length of the key to use in Bytes', | ||
default: 32 | ||
}, | ||
'out': { | ||
short: 'o', | ||
describe: 'File location to write result to' | ||
} | ||
}); | ||
var secret = nconf.get('secret'); | ||
if (nconf.get('iterations')) { | ||
krypt.setIterations(nconf.get('iterations')); | ||
} | ||
if (nconf.get('length')) { | ||
krypt.setKeyLength(nconf.get('length')); | ||
} | ||
if (nconf.get('encrypt')) { | ||
@@ -29,0 +66,0 @@ |
@@ -10,3 +10,8 @@ /*! | ||
var CYPHER = 'aes-256-cbc', | ||
KEY_DERIVATION = 'pbkdf2', | ||
DEFAULT_KEY_LENGTH = 32, | ||
DEFAULT_ITERATIONS = 64000; | ||
module.exports = new Krypt(); | ||
@@ -23,3 +28,4 @@ exports.Krypt = Krypt; | ||
this.iterations = config.iterations || 2000; | ||
this.iterations = config.iterations || DEFAULT_ITERATIONS; | ||
this.keyLength = config.keyLength || DEFAULT_KEY_LENGTH; | ||
this.defaultSecret = config.secret; | ||
@@ -38,3 +44,7 @@ } | ||
Krypt.prototype.setKeyLength = function setKeyLength(keyLength) { | ||
this.keyLength = keyLength; | ||
}; | ||
Krypt.prototype.encrypt = function encrypt(input, secret) { | ||
@@ -51,10 +61,9 @@ | ||
var salt = crypto.randomBytes(4), | ||
iv = crypto.randomBytes(16), | ||
keyLength = 32; | ||
var salt = crypto.randomBytes(this.keyLength), | ||
iv = crypto.randomBytes(16); | ||
try { | ||
var key = crypto.pbkdf2Sync(secret, salt, this.iterations, keyLength), | ||
cipher = crypto.createCipheriv('aes-256-cbc', key, iv); | ||
var key = crypto.pbkdf2Sync(secret, salt, this.iterations, this.keyLength), | ||
cipher = crypto.createCipheriv(CYPHER, key, iv); | ||
@@ -65,2 +74,6 @@ var encryptedValue = cipher.update(input, 'utf8', 'base64'); | ||
return { | ||
cypher: CYPHER, | ||
keyDerivation: KEY_DERIVATION, | ||
keyLength: this.keyLength, | ||
iterations: this.iterations, | ||
iv: iv.toString('base64'), | ||
@@ -107,8 +120,9 @@ salt: salt.toString('base64'), | ||
iv = new Buffer(input.iv, 'base64'), | ||
keyLength = 32; | ||
keyLength = input.keyLength || this.keyLength, | ||
iterations = input.iterations || this.iterations; | ||
try { | ||
var key = crypto.pbkdf2Sync(secret, salt, this.iterations, keyLength), | ||
decipher = crypto.createDecipheriv('aes-256-cbc', key, iv); | ||
var key = crypto.pbkdf2Sync(secret, salt, iterations, keyLength), | ||
decipher = crypto.createDecipheriv(CYPHER, key, iv); | ||
@@ -115,0 +129,0 @@ var decryptedValue = decipher.update(input.value, 'base64', 'utf8'); |
{ | ||
"name": "krypt", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Simple, secure symmetric encryption utility for Node.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -50,4 +50,4 @@ Krypt: Simple, Secure, Symmetric Encryption | ||
+ CBC | ||
+ Key Stretching w/ PBKDF2 | ||
+ Key Stretching w/ PBKDF2 @ 64,000 iterations | ||
+ Random IV / encrypted value | ||
+ Random salt / encrypted value |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11202
252