mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
major security update
This commit is contained in:
46
server/node_modules/node-cryptojs-aes/lib/jsonformatter.js
generated
vendored
Normal file
46
server/node_modules/node-cryptojs-aes/lib/jsonformatter.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
var CryptoJS = require('./core').CryptoJS;
|
||||
|
||||
// create custom json serialization format
|
||||
var JsonFormatter = {
|
||||
stringify: function (cipherParams) {
|
||||
// create json object with ciphertext
|
||||
var jsonObj = {
|
||||
ct: cipherParams.ciphertext.toString(CryptoJS.enc.Base64)
|
||||
};
|
||||
|
||||
// optionally add iv and salt
|
||||
if (cipherParams.iv) {
|
||||
jsonObj.iv = cipherParams.iv.toString();
|
||||
}
|
||||
|
||||
if (cipherParams.salt) {
|
||||
jsonObj.s = cipherParams.salt.toString();
|
||||
}
|
||||
|
||||
// stringify json object
|
||||
return JSON.stringify(jsonObj)
|
||||
},
|
||||
|
||||
parse: function (jsonStr) {
|
||||
// parse json string
|
||||
var jsonObj = JSON.parse(jsonStr);
|
||||
|
||||
// extract ciphertext from json object, and create cipher params object
|
||||
var cipherParams = CryptoJS.lib.CipherParams.create({
|
||||
ciphertext: CryptoJS.enc.Base64.parse(jsonObj.ct)
|
||||
});
|
||||
|
||||
// optionally extract iv and salt
|
||||
if (jsonObj.iv) {
|
||||
cipherParams.iv = CryptoJS.enc.Hex.parse(jsonObj.iv);
|
||||
}
|
||||
|
||||
if (jsonObj.s) {
|
||||
cipherParams.salt = CryptoJS.enc.Hex.parse(jsonObj.s);
|
||||
}
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
};
|
||||
|
||||
exports.JsonFormatter = JsonFormatter;
|
||||
Reference in New Issue
Block a user