# Decrypt the given encrpted data using AES-256-GCM alogirthm with key and IV

**URL:** <https://community.postman.com/t/decrypt-the-given-encrpted-data-using-aes-256-gcm-alogirthm-with-key-and-iv/39721>\
**Category:** Help Hub\
**Tags:** tests, authentication\
**Created:** [October 3, 2022, 11:47am UTC](https://community.postman.com/t/decrypt-the-given-encrpted-data-using-aes-256-gcm-alogirthm-with-key-and-iv/39721 "2022-10-03T11:47:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanaja17](https://avatars.discourse-cdn.com/v4/letter/v/4af34b/32.png) [@vanaja17](https://community.postman.com/u/vanaja17)\
**Post date:** [October 3, 2022, 11:47am UTC](https://community.postman.com/t/decrypt-the-given-encrpted-data-using-aes-256-gcm-alogirthm-with-key-and-iv/39721/1 "2022-10-03T11:47:07Z")

</div>

const \_crypto = require(‘crypto-js’);

const decryptAes256Gcm = (encdata) =\> {  
try {  
// base64 decoding  
const bData = Buffer.from(encdata, ‘base64’);  
// convert data to buffers  
const iv = 12;  
const tag = bData.slice(80, 96);  
const text = bData.slice(96);  
// derive key using; 32 byte key length  
const key = ‘fgrtheForbtgkpeNQ4MM0+LvfEdj1MUh8/gjh5Ur0=’ ;  
// AES 256 GCM Mode  
const decipher = \_crypto.createDecipheriv(‘aes-256-gcm’, key, iv);  
decipher.setAuthTag(tag);  
return decipher.update(text, ‘binary’, ‘utf8’) + decipher.final(‘utf8’)  
} catch (err) {  
return err  
}  
}  
// ======================== //////// ==========================

const encryptedData = ‘"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJwa2dKMkhsenpudDhLWEkyMH’;  
console.log(‘decrypted data -\>’, decryptAes256Gcm(encryptedData))
