Hello !
So, I’m trying to use Toolbox’s “Server Script” action to decrypt an 128-AES-CBC encrypted token.
Why server side? Because it seems to me that running a decrypting script on the client side would expose the private key, but I may be wring on this.
The script needs to accept:
- An encrypted token (probably encoded in base64)
- An Initiation Vector
- A private key
And it should return the decrypted output in plain text, or an error if the decryption didn’t work out.
I came up with this node.js script:
const crypto = require(‘crypto’);
function decryptToken(token, iv, secretKey) {
try {
const decipher = crypto.createDecipheriv(‘aes-128-cbc’, secretKey, iv);
let decrypted = decipher.update(token, ‘base64’, ‘utf8’);
decrypted += decipher.final(‘utf8’);
return decrypted;
} catch (err) {
console.error(err);
return null;
}
}
const token = ‘your_encrypted_token’;
const iv = Buffer.from(‘your_iv’);
const secretKey = Buffer.from(‘your_secret_key’);
const decryptedToken = decryptToken(token, iv, secretKey);
if (decryptedToken) {
console.log(decryptedToken);
} else {
console.error(‘Decryption failed’);
}
I created the following Server Script action on a test page:
With data’s “Arbitrary text” being MKomzoTUb7qvh9BWioEv5g==
And Thing 1’s “Arbitrary text” being 1234123412341234
The test private key is directly in the code: sandbox-xyzx-key
In the workflow, a subsequent action saves the return of this Server Script action.
And… it doesn’t work
There are no js error code while running it, but the return is empty.
I may have tried to many new things at once:
- server script
- data manipulating js in Bubble
- crypto node.js
I someone could gave me a hint on how to solve that one, that’d be great!