File is generated successfully but when trying to open file, it is in invalid gzip format after decryption. Shows error unsupported format and failing to decompress.
zlib.gzip("Hello World", async (err, compressedData) => {
if (err) {
console.error('Error compressing data:', err);
return;
}
try {
const message = await openpgp.createMessage({ text: compressedData.toString() });
const publicKeyObj = await openpgp.readKey({ armoredKey: publicKeyForEncryption });
const encryptedData = await openpgp.encrypt({ message, encryptionKeys: publicKeyObj });
// Save the compressed and encrypted data to a file
fs.writeFile('/path_to_file/output.txt.gz.gpg', encryptedData, (error) => {
if (error) {
console.error('Error saving compressed data to file:', error);
return;
}
console.log('Data compressed and saved to file successfully.');
});
} catch (error) {
console.error('Error encrypting data:', error);
}
});
Tried using zlib and openpgp(5.9.0) modules. Expecting the end file to be in format .txt.gz.gpg and should be able to decrypt and decompress to see the text file output.txt with Hello World as text inside the file.