Skip to content

Instantly share code, notes, and snippets.

@uso5
Created March 7, 2019 12:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uso5/74ec35793e1327e487ba03c479b0814c to your computer and use it in GitHub Desktop.
Save uso5/74ec35793e1327e487ba03c479b0814c to your computer and use it in GitHub Desktop.
Nodejs snippet to decrypt intercom user submitted by Open sheet flow - https://developers.intercom.com/building-apps/docs/sheets-flow#section-open-sheet-flow
const masterkey = 'your-master-key';
// base64 decoding
const bData = Buffer.from(decoded, 'base64');
// convert data to buffers
const ivlen = 12;
const iv = bData.slice(0, ivlen);
const taglen = 16;
const tag = bData.slice(bData.length - taglen, bData.length);
const cipherLen = bData.length - taglen;
const cipherText = bData.slice(ivlen, cipherLen);
let hash = crypto.createHash('sha256').update(masterkey);
let key = Buffer.from(hash.digest("binary"), "binary");//buffer from binary string.
// AES 256 GCM Mode
const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv);
decipher.setAuthTag(tag);
// encrypt the given text
let decrypted = decipher.update(cipherText, 'binary', 'utf8');
decrypted += decipher.final('utf8');
console.log(decrypted);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment