首页 > 解决方案 > 如何解压缩变量中的数据(在 Post Man 中,使用 json,并且已经完成解密)?

问题描述

我正在使用 javascript 编写 Post Man 测试,以验证 api 响应的某个部分是否正确。整个 api 响应以 json 形式返回。但是,这个 json 响应的一部分是 base64 加密、128 位加密和压缩的。因此,我将 json 响应的这一部分存储在一个变量中。然后,我对它进行 base 64 解码并将其存储到第二个变量中。最后,我 128 位解密并将其存储到第三个变量中。

我现在的问题是我想解压缩第三个变量中的数据。需要明确的是,这现在是从服务器返回的原始 api 响应的子集。它已经过 base64 解码和 128 位解密。现在,我需要解压缩它。我发现的所有研究都涉及解压缩 .zip 文件。我无法使用它,因为我没有将此信息存储在文件中。我将此信息存储在一个变量中。

那么,是否有人能够解压缩存储在变量中而不是存储在 .zip、.jar 或其他文件类型中的数据?

======================================== 让你理解起来也更直观,这是我正在尝试的一个紧密示例:

var jsonData = pm.response.json();

//rawResponse is a subset of the json response, and the part we need to test later, but here its still encrypted and compressed
var rawResponse = jsonData.field[2].data;  

//base 64 decode
var base64Decoded = atob(rawResponse);

//our key for the 128 bit decryption
var key = 1234ourmadeupkeyhere;  //actual key works when used, but obviously not listed here

//Do the 128 bit decrypting
var decryptedData = CryptoJS.AES.decrypt(base64Decoded, key);

//In this variable decompressedData, this is the data we need to decompress
var decompressedData = howDoIDecompressThisHere(decryptedData );

//Assertion
pm.expect(decompressedData).to.be.equal("blahblahblah something readable and no longer compressed");```

标签: jsonencryptionpostman

解决方案


推荐阅读