将数据从base 64解密为二进制后,我想解压缩该数据。
在PHP语言中,我们具有gzdecode()内置函数,但是我在项目中使用node js,而且我不知道如何使用gzip解压缩二进制数据。我在请求正文中获得了加密数据,然后将其解密,然后想要解压缩解密的数据。完成此步骤后,我将解密后的数据存储在mongodb数据库中
我的代码用于将数据从base 64解密为二进制形式
function decrypt(text, salt, iv) {
const password = "password";
crypto.pbkdf2(password, salt, 65536, 256, "sha256", (err, key) => {
try {
const key32 = key.slice(0, 32);
const decipher = crypto.createDecipheriv("aes-256-cbc", key32, iv);
let decrypted = decipher.update(text, "base64", "binary");
decrypted += decipher.final("binary");
// and then I want decompress my `decrypted` variable
// like gzdecode(decrypted) in php
} catch (error) {
throw new Error(error)
}
});
}
decrypt(plainText, salt, iv)
Node.js具有内置的ZLib支持。解密完成后,您可以使用zlib.unzip(https://nodejs.org/api/zlib.html#zlib_zlib_unzip_buffer_options_callback)或zlib.unzipSync(https://nodejs.org/api/zlib.html#zlib_zlib_zlib_unzipsync_buffer_options)解压缩或为Inflate进行inflate / inflateSync(https://nodejs.org/api/zlib.html#zlib_zlib_inflate_buffer_options_callback)
希望有帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句