Encryption/decryption library for Google Apps Script.
Amit Agarwal recently showed how to encrypt/decrypt Email messages using a Google Apps Script application in this post The encryption method he used is SJCL, maintained by the Stanford Security Lab, and available on GITHUB here.
I needed something like that for a Google Apps Script version of a parse.com API (here’s the VBA version) that I’m just finishing up, so I thought I may as well share out the library.
The library contains a Google Apps Script version of SJCL, but it’s exposed by these simple functions
function encryptMessage (s,salt) { return Utilities.base64Encode(JSON.stringify(sjcl.encrypt(salt,s))); } function decryptMessage (s,salt) { return sjcl.decrypt(salt,JSON.parse(Utilities.newBlob(Utilities.base64Decode(s)).getDataAsString())); }
These can be included in your project by referencing this library in your GAS project
MphGZav4pHGf9EQx-JdmO7yz3TLx7pV4j
To encrypt strings in you project, you can do this;
var codedString = sjclEncryption.encryptMessage ( "your data string", "your passPhrase");
and for restoring the original text;
var plainString = sjclEncryption.encryptMessage ( codedString, "your passPhrase");
Happy encrypting.