Hello,
I have made a connection with a RESTfull service.
It provide the response is a json file.
The content is encrypted and should be decrypted.
We also have a base64 SecureKey
It could look like (due to confidential data, i am not able to expose the real tag, and the content has been truncated).
{
“content”: “a5fdcf3b4d11d”,
“tag”: “c1b2f1169a71bc15bfb12a11bb3a1796,”,
“iv”: “d12b415cea13583f14a29141”,
“key_id”: “1”
}
The content is just Encrypted Plain text.
Tag and IV are both hexadecimal code.
And the securekey is base 64.
My question is how to decrypt this information within Studio 21.10.8 in windows compatibility mode.
I already tried the Uitpath.Cryptography.Activities.DecryptText activity.
where we don’t need to provide the Tag and Iv, but i get the message:
Decrypt JSON content using AES GCM algorithm: A cryptographic operation has failed. Please make sure you use the same algorithm and key for both encryption and decryption operations.
I tried quite a lot, but i am not sure how to solve this issue.
I also tried to use some vb code, but for whatever reason this does not work properly.
The people that created the Service provides me with the below shown JS Node script.
When i fill in the data from the Json file between the “” or ‘’ i get a perfect result back.
So i hope that there is someone who can help me out with this issue.
Thanks in advance
const crypto = require(‘crypto’);
const encryptedText = “”;
const authTag = Buffer.from(‘’, ‘hex’);
const iv = Buffer.from(‘’, ‘hex’);
const key = Buffer.from(‘’, ‘base64’);
function decryptAES256GCM(encryptedText, key, iv, authTag) {
const decipher = crypto.createDecipheriv(‘aes-256-gcm’, key, iv);
decipher.setAuthTag(authTag);
let decrypted = decipher.update(encryptedText, ‘hex’, ‘utf8’);
decrypted += decipher.final(‘utf8’);
return decrypted;
}
// Example usage
try {
const decryptedText = decryptAES256GCM(encryptedText, key, iv, authTag);
console.log(‘Decrypted text:’, decryptedText);
} catch (err) {
console.error(‘Decryption failed:’, err.message);
}