Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.