This is my Anguarjs Code
$httpProvider.defaults.headers.common['key'] = CryptoJS.AES.encrypt('<datatoencrypt>', '<key let says xyx>=', {
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
keySize: '256 / 32'
});
Node JS Code To decrypt using, algorithm as aes-256-cbc and key as same as angular.
app.all('*', function (req, res, next) {
var headers = JSON.parse(JSON.stringify(req.headers));
var decipher = crypto.createDecipher(algorithm, key);
decipher.setAutoPadding(true);
var dec = decipher.update(headers.key, 'hex', 'utf8');
dec += decipher.final('utf8');
if (dec != "<datatoencrypt>")
{
//do something
next();
}
else
{
//do something
next();
}});
I am unable to decrypt the encryption done in angular. They both work fine if used in itself. if i decrypt the string in angular itself it work same goes for node. But Cross platform its not working can anyone suggest what is wrong with my approach. Any help would be appreciated. I have tried removing autopadding form both sides as well, also buffers encrypt/decrypt is not working. Thanks in advance.