Shared Encryption/decryption library for Google Apps Script.

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.

About brucemcp 224 Articles
I am a Google Developer Expert and decided to investigate Google Apps Script in my spare time. The more I investigated the more content I created so this site is extremely rich. Now, in 2019, a lot of things have disappeared or don’t work anymore due to Google having retired some stuff. I am however leaving things as is and where I came across some deprecated stuff, I have indicated it. I decided to write a book about it and to also create videos to teach developers who want to learn Google Apps Script. If you find the material contained in this site useful, you can support me by buying my books and or videos.

Be the first to comment

Leave a Reply

Your email address will not be published.


*