Last active
April 18, 2018 11:16
-
-
Save tjokimie/e164adf23959c46a32523a17d5e01fcf to your computer and use it in GitHub Desktop.
Decrypting Iron sealed JSON in Postman
This file contains hidden or 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
function decrypt(token) { | |
var password = pm.environment.get('YOUR_PASSWORD_ENV_VARIABLE_NAME'); | |
var iterations = 1; | |
var keySize = 256; | |
var parts = token.split('*'); | |
var encryptionSalt = parts[2]; | |
var encryptionIv = parts[3]; | |
var encryptedB64 = parts[4]; | |
var ct = CryptoJS.enc.Base64.parse(Buffer.from(encryptedB64, 'base64').toString('base64')); | |
var secretKey = CryptoJS.PBKDF2(password, encryptionSalt, { | |
keySize: keySize / 32, | |
iterations: iterations | |
}); | |
var iv = CryptoJS.enc.Base64.parse(Buffer.from(encryptionIv, 'base64').toString('base64')); | |
var decrypted = CryptoJS.AES.decrypt({ ciphertext: ct }, secretKey, { | |
iv: iv, | |
mode: CryptoJS.mode.CBC, | |
padding: CryptoJS.pad.Pkcs7 | |
}); | |
return JSON.parse(decrypted.toString(CryptoJS.enc.Utf8)); | |
} | |
var data = JSON.parse(responseBody); | |
var decrypted = decrypt(data); | |
pm.environment.set('YOUR_TOKEN_ENV_VARIABLE_NAME', decrypted.token); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment