Question: how can I run this code on bubble: it is working fine on this website (https://onecompiler.com/javascript/) but when loaded to “toolbox” JavaScript to bubble it fails
Here is the code below
// No direct equivalent for System.Security.Cryptography in JavaScript
const crypto = require(‘crypto’);
console.log(“Encrypting Payout Account Number”);
var plaintextEncryptionKey = “[ENCRYPTION KEY]”;
var plaintextAccountNumber = “[PLAIN TEXT ACCOUNT NUMBER]”;
var merchantReference = “[MERCHANT REFERENCE]”;
var payoutAmount = 17.15;
var ivString = merchantReference + parseInt(payoutAmount * 100) + plaintextEncryptionKey;
var encryptedAccountNumber = encryptAes(plaintextAccountNumber, plaintextEncryptionKey, ivString);
console.log("Hash before encryption: " + ivString);
console.log("Encrypted account number: " + encryptedAccountNumber);
function encryptAes(data, key, ivString) {
var dataBytes = Buffer.from(data, “utf8”);
var encryptedBytes;
var iv = getSha512Hash(ivString.toLowerCase()).substring(0, 16);
while (key.length < 32) {
key += key;
}
var aes = crypto.createCipheriv(“aes-256-cbc”, key.substring(0, 32), iv);
encryptedBytes = Buffer.concat([aes.update(dataBytes), aes.final()]);
aes = null;
return encryptedBytes.toString(“base64”);
}
function decryptAes(encrypted, key, ivString) {
encrypted = encrypted.replace(/\s/g, “+”);
var encryptedBytes = Buffer.from(encrypted, “base64”);
var dataBytes;
var iv = getSha512Hash(ivString.toLowerCase()).substring(0, 16);
while (key.length < 32) {
key += key;
}
var aes = crypto.createDecipheriv(“aes-256-cbc”, key.substring(0, 32), iv);
dataBytes = Buffer.concat([aes.update(encryptedBytes), aes.final()]);
aes = null;
return dataBytes.toString(“utf8”);
}
function getSha512Hash(stringToHash) {
var alg = crypto.createHash(“sha512”);
var hash = alg.update(stringToHash, “utf8”).digest(“hex”);
return hash;
}