The value of the data input is encoded with a AES-128 mechanism, where the first 16 characters is the client_secret of my application, which serves as a key to the decoding process.I tried to decode it,it not work. The code I tried `
const express=require('express');
const bodyParser=require('body-parser');
var app=express();
var crypto=require('crypto');
app.use(express.static(__dirname+'/public'));
app.use(bodyParser.urlencoded({extended:true}));
app.post('/',(req,res)=>{
var app_secret_key="my secret key";
var abc=JSON.stringify(req.body.data);
var key_app_secret_key=app_secret_key.substring(0,16);
function decrypt(key,data){
var decipher = crypto.createDecipher('aes-128-cbc',key);
var decrypted = decipher.update(data,'binary', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
console.log(decrypt(key_app_secret_key,abc));
});
app.listen(3000,()=>{
console.log('Server running in port 3000');
})
` The error I am getting attach below. Please advise me how to solve this issue. Thanks in advance.
Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
at Decipher.final (crypto.js:183:26)
at decrypt (c:\xampp\htdocs\cameacoins\encryptPract\app.js:18:25)
at app.post (c:\xampp\htdocs\cameacoins\encryptPract\app.js:22:14)
at Layer.handle [as handle_request] (c:\xampp\htdocs\cameacoins\node_modules\express\lib\router\layer.js:95:5)
at next (c:\xampp\htdocs\cameacoins\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (c:\xampp\htdocs\cameacoins\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (c:\xampp\htdocs\cameacoins\node_modules\express\lib\router\layer.js:95:5)
at c:\xampp\htdocs\cameacoins\node_modules\express\lib\router\index.js:281:22
at Function.process_params (c:\xampp\htdocs\cameacoins\node_modules\express\lib\router\index.js:335:12)
at next (c:\xampp\htdocs\cameacoins\node_modules\express\lib\router\index.js:275:10)