Created
March 7, 2019 12:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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