# Help with Javascrpt to bubble

**URL:** <https://forum.bubble.io/t/help-with-javascrpt-to-bubble/305818>\
**Category:** APIs\
**Created:** [February 4, 2024, 6:38pm UTC](https://forum.bubble.io/t/help-with-javascrpt-to-bubble/305818 "2024-02-04T18:38:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sibabongani](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@sibabongani](https://forum.bubble.io/u/sibabongani)\
**Post date:** [February 4, 2024, 6:38pm UTC](https://forum.bubble.io/t/help-with-javascrpt-to-bubble/305818/1 "2024-02-04T18:38:30Z")

</div>

Question: how can I run this code on bubble: it is working fine on this website ([https://onecompiler.com/javascript/](https://onecompiler.com/javascript/)) but when loaded to “toolbox” JavaScript to bubble it fails

**Here is the code below**

 ![IMG_7926](https://us1.discourse-cdn.com/bubble/original/3X/e/4/e4af2770719395af0fcf36060036ddd2f63998b1.jpeg)  
 ![Image 2024-02-04 at 19.34](https://us1.discourse-cdn.com/bubble/original/3X/d/a/dac5f92477be10d466e300c6ac9b41ef6495120a.jpeg)

// 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;  
}

---

<div class="post-metadata">

**Author:** ![Eugene\_West](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/eugene_west/32/106508_2.png) [@Eugene\_West](https://forum.bubble.io/u/Eugene_West)\
**Post date:** [February 4, 2024, 8:16pm UTC](https://forum.bubble.io/t/help-with-javascrpt-to-bubble/305818/2 "2024-02-04T20:16:25Z")

</div>

You are trying to run the server script on the client side.  
It should on the backend workflow and action “Server script”
