Add AES Encrypt/Decrypt Functions to Google Sheet

I recently needed to add some sensitive data to a database which was later going to be sent to a Google Sheet. Now, the situation was such that the sensitive data can lie unencrypted in the Google Sheet but no on the database. I tried looking at Sheets formulae definition to find if there were inbuilt encryption and decryption functions. There aren’t. So, I decided to create one for myself.

Here’s the Github Gist that you can add to your Sheet’s AppScript Engine to get AES encryption/decryption capability in your sheet:

https://gist.github.com/ameyanekar/be20cbb775c4d89c87e37c55994a7240

The above code will create two functions for you:

encrypt(plaintext)
decrypt(ciphertext)

Update the asciiKey variable to adjust the key, or even better, pass the key in the function from the sheet.