Comparing version 0.2.2 to 0.2.3
23
index.js
@@ -13,12 +13,13 @@ /* jslint node: true */ | ||
JSON.cryptPassword = 'none'; | ||
JSON.cryptAlgorithm = 'aes-256-ctr'; | ||
JSON.cryptPassword = crypto.randomBytes(32); | ||
JSON.cryptAlgorithm = 'AES-256-CBC'; | ||
JSON.encrypt = function(data,password,algorithm){ | ||
JSON.encrypt = function(data, password, algorithm){ | ||
password = password || JSON.cryptPassword; | ||
algorithm = algorithm || JSON.cryptAlgorithm; | ||
var iv = new Buffer(crypto.randomBytes(16)); | ||
try { | ||
data = JSON.decycled(data); | ||
var cipher = crypto.createCipher(algorithm,password); | ||
data = cipher.update(data,'utf8','hex'); | ||
var cipher = crypto.createCipheriv(algorithm, password, iv); | ||
data = cipher.update(data, 'utf8', 'hex'); | ||
data += cipher.final('hex'); | ||
@@ -29,12 +30,14 @@ } catch(error){ | ||
} | ||
return data; | ||
return iv.toString('hex') + ':' + data; | ||
}; | ||
JSON.decrypt = function(data,password,algorithm){ | ||
data = data || ''; | ||
JSON.decrypt = function(data, password, algorithm){ | ||
data = (data || '').split(':'); | ||
var iv = new Buffer(data[0], 'hex'); | ||
data = data[1]; | ||
password = password || JSON.cryptPassword; | ||
algorithm = algorithm || JSON.cryptAlgorithm; | ||
var decipher = crypto.createDecipher(algorithm,password); | ||
var decipher = crypto.createDecipheriv(algorithm, password, iv); | ||
try { | ||
data = decipher.update(data,'hex','utf8'); | ||
data = decipher.update(data, 'hex', 'utf8'); | ||
data += decipher.final('utf8'); | ||
@@ -41,0 +44,0 @@ data = JSON.revive(data); |
{ | ||
"name": "json.crypt", | ||
"description": "Javascript object encryt utility for Node.js", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Bifuer", |
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
3468
42