This is a 4 year old nodejs project I took over, and I was asked to refactor it using golang, but in the refactoring I found that the nodejs encryption was deprecated. And, I don't know which mode of AES is used to encrypt this code
Can any expert help me to see how to decrypt this nodejs encryption with golang? Thank you very much!
Encryption code for nodejs :
exports.createToken = function (src: string, timestamp: string, key: any) {
var msg = src + '|' + timestamp;
var cipher: any = CryptoJS.createCipher('aes256', key);
var enc: any = cipher.update(msg, 'utf8', 'hex');
enc += cipher.final('hex');
return enc;
};
Decryption code for nodejs :
exports.parseToken = function (token: string, key: string): any {
let decipher = CryptoJS.createDecipher('aes256', key);
let dec: string;
try {
dec = decipher.update(token, 'hex', 'utf8');
dec += decipher.final('utf8');
} catch (err) {
console.error('[token] fail to decrypt token. %j', token);
return null;
}
var ts = dec.split('|');
if (ts.length !== 2) {
// illegal token
return null;
}
return { src: ts[0], timestamp: Number(ts[1]) };
};