// encrypt some bytes using ECB mode
var cipher = forge.cipher.createCipher('AES-ECB', key);
cipher.start();
cipher.update(forge.util.createBuffer(packedFile));
cipher.finish();
var encrypted = cipher.output;
// decrypt some bytes using ECB mode
var decipher = forge.cipher.createDecipher('AES-ECB', key);
decipher.start();
decipher.update(encrypted);
decipher.finish(); // check 'result' for true/false
// outputs decrypted
console.log(msgpack.unpack(decipher.output.data))
});
But I am getting this error in this line:
console.log(msgpack.unpack(decipher.output.data))
Uncaught TypeError: First argument must be a Buffer
I am trying to excute this code that do
read json file
change json to message pack
encrypt the new json
decypt the new json
change json message pack to normal json (here is my error)
var fs = require('fs'); var forge = require('node-forge'); var msgpack = require('msgpack');
file = [] x= null fs.readFile(process.cwd() + "/test.json", function(err, data) { file = data // json = JSON.stringify(JSON.parse(file),null,2); packedFile = msgpack.pack(file) key = 'SdI6qAn1602f942'
// encrypt some bytes using ECB mode var cipher = forge.cipher.createCipher('AES-ECB', key); cipher.start(); cipher.update(forge.util.createBuffer(packedFile)); cipher.finish(); var encrypted = cipher.output;
// decrypt some bytes using ECB mode var decipher = forge.cipher.createDecipher('AES-ECB', key); decipher.start(); decipher.update(encrypted); decipher.finish(); // check 'result' for true/false // outputs decrypted console.log(msgpack.unpack(decipher.output.data)) });
But I am getting this error in this line:
console.log(msgpack.unpack(decipher.output.data)) Uncaught TypeError: First argument must be a Buffer
My test file is any json file
{ "testin": "test" }