Reputation: 501
After I decrypt data from base 64 to binary, I want to unzip this data.
In PHP language, we have gzdecode() built-in function, but I use node js in my project, and I don't know how I can decompress binary data using gzip. I get encryption data in request body, then I decrypted it and then I want unzip my decrypted data. After this steps I store decrypted data in my mongodb database
My code for decrypt data from base 64 to binary form
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)
Upvotes: 2
Views: 1964
Reputation: 411
Node.js has built-in ZLib support. Once you are done decrypting, you can use:
zlib.unzip
or zlib.unzipSync
for unzippinginflate
or inflateSync
for InflatingHope that helps!
Upvotes: 3