-
OpenPGP.js version 5.1 I would like to encrypt a zip file using OpenPGP.js (https://browserpgp.github.io/). All processing needs to be done on the client-side, without involvement of Node.js. Using the javascript-based browserpgp.js, encryption of plaintext file is easy, but encryption of zip files are challenging. I am attaching the code I use to encrypt the zip file. Since, the contents of zip file are not text, so I have used guides for working with binary data from https://github.com/openpgpjs/openpgpjs. I believe the resulting file after encryption of a zip file should be in raw/binary format, and the resulting file saved from the following encryption code is in binary. However, I verified it and its cannot be decrypted. I am using the Kleopatra desktop OpenPGP tool (https://www.openpgp.org/software/kleopatra/) to verify if the resulting encrypted file. Using the tool, I tested to see if I can decrypt the encrypted file using my private key. The resulting binary file cannot be decrypted using the Kleopatra tool. So I was wondering what is wrong with this code, as the resulting file should be decryptable using Kleopatra. You can create two public keys using the tool here: https://browserpgp.github.io/
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 10 replies
-
Also, |
Beta Was this translation helpful? Give feedback.
-
Thank you so much twiss. Your answer works. |
Beta Was this translation helpful? Give feedback.
-
For anyone looking, here is the decryption code, which is called from the above OpenPGPEncryptDataZipFile function
|
Beta Was this translation helpful? Give feedback.
-
Hi twiss, I tried to use passphrase based approach to encrypt the key. I generated and use another set of pub-pri keys with the Privkey Passphrase. But upon decryption of the encrypted zip file using the private key, and providing the passphrase, it gives the following error.
Everything is exactly the same, with the following additional code. Would be glad if I can get help me out here.
|
Beta Was this translation helpful? Give feedback.
-
Thanks twiss, it works. In a bit more detail:
|
Beta Was this translation helpful? Give feedback.
new Uint8Array(zipBlob)
most likely doesn't do what you think it does. Perhaps trynew Uint8Array(await zipBlob.arrayBuffer())
, or just ask JSZip for a Uint8Array instead of a Blob in the first place.Also,
octet/stream
is not a valid MIME type. Perhaps you meantapplication/octet-stream
?