we have been using xxtea-node npm package for encryption and decryption, as we can see the plugin is depended on Buffer node package, but during the decryption process, it throws Undefined error as below.
Environment :
Node : V14.17.3,
NPM : 6.14.13,
Encryption plugin : xxtea-nodejs
Decyption method which throwing error :
function decrypt(data, key) {
if (typeof data === 'string') data = new Buffer(data, 'base64'); //This line throws Undefined error
if (typeof key === 'string') key = toBytes(key);
if (data === undefined || data === null || data.length === 0) {
return data;
}
return toUint8Array(decryptUint32Array(toUint32Array(data, false), toUint32Array(fixk(key), false)), true);
}
In the Decrypt method new Buffer line is throwing "ReferenceError: Buffer is not defined", but if I replace this line with the following line it works fine require('buffer/').Buffer.from()
Whats the difference between both and how to fix the first said issue?