2

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)
Elli Zorro
  • 463
  • 3
  • 19
  • 1
    Possible duplicate of [How do I ungzip (decompress) a NodeJS request's module gzip response body?](https://stackoverflow.com/questions/12148948/how-do-i-ungzip-decompress-a-nodejs-requests-module-gzip-response-body) – James Oct 06 '19 at 11:46
  • I don't think so – Elli Zorro Oct 06 '19 at 11:48

1 Answers1

3

Node.js has built-in ZLib support. Once you are done decrypting, you can use:

Hope that helps!

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Alex Stepanov
  • 391
  • 1
  • 5