Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
Cifrar un archivo zip con la herramienta javascript browserpgp

Me gustaría encriptar un archivo zip usando OpenPGP.js ( https://browserpgp.github.io/ ). Todo el procesamiento debe realizarse en el lado del cliente, sin la participación de Node.js. Con el navegador pgp.js basado en javascript, el cifrado del archivo de texto sin formato es fácil, pero el cifrado de los archivos zip es un desafío. Adjunto el código que utilizo para cifrar el archivo zip. Dado que el contenido del archivo zip no es texto, he usado guías para trabajar con datos binarios de https://github.com/openpgpjs/openpgpjs . Creo que el archivo resultante después del cifrado de un archivo zip debe estar en formato sin formato/binario, y el archivo resultante guardado del siguiente código de cifrado está en binario. Sin embargo, lo verifiqué y no se puede descifrar.

Estoy usando la herramienta OpenPGP de escritorio de Kleopatra ( https://www.openpgp.org/software/kleopatra/ ) para verificar si el archivo encriptado resultante. Usando la herramienta, probé para ver si podía descifrar el archivo encriptado usando mi clave privada. El archivo binario resultante no se puede descifrar con la herramienta Kleopatra. Así que me preguntaba qué está mal con este código, ya que el archivo resultante debería poder descifrarse usando Kleopatra.

Puede crear dos claves públicas usando la herramienta aquí: https://browserpgp.github.io

 function openpgp_encryptZIPFile(){ var zip = new JSZip(); zip.file("Hello.txt", "Hello World\n"); var img = zip.folder("images"); zip.generateAsync({type:"blob"}) .then(function(content) { console.log('contents: ' + content); encryptedZipFile = OpenPGPEncryptDataZipFile(content); }); } async function OpenPGPEncryptDataZipFile(zipBlob) { //This is my public key const key1 = `somekey1`; //you would have to put a public key here //This is the testuser public key const key2 = `somekey2`; //you would have to put another public key here const publicKeysArmored = [key1, key2]; //create a combined key const publicKeys = await Promise.all(publicKeysArmored.map(armoredKey => openpgp.readKey({ armoredKey }))); var binaryData = new Uint8Array(zipBlob); //https://github.com/openpgpjs/openpgpjs/blob/main/README.md //For OpenPGP.js v4 syntax is: const message = openpgp.Message.fromBinary(binaryData); //For OpenPGP.js v5 syntax is: const message2 = await openpgp.createMessage({ binary: binaryData }); //`const {data: encrypted}' OR `const { message }' OR just `const encrypted' const encrypted = await openpgp.encrypt({ message: await openpgp.createMessage({ binary: binaryData }), encryptionKeys: publicKeys, //signingKeys: privateKey // optional format: 'binary' }); console.log('encrypted: ' + encrypted); var encryptedBlob = new Blob([encrypted],{type: 'text/plain'}); //var encryptedBlob = new Blob([encrypted], {type: "octet/stream"}); saveAs(encryptedBlob, 'test.zip.enc' ); }
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Alguien de OpenPGPjs github repo respondió esto

Lo más probable es que new Uint8Array(zipBlob) no haga lo que cree que hace. Tal vez pruebe new Uint8Array(await zipBlob.arrayBuffer()) , o simplemente solicite a JSZip un Uint8Array en lugar de un Blob en primer lugar.

Además, octet/stream no es un tipo MIME válido. ¿Quizás quisiste decir application/octet-stream?

Así que cambié new Uint8Array(zipBlob) a new Uint8Array(await zipBlob.arrayBuffer()) y funcionó.

https://github.com/openpgpjs/openpgpjs/discusiones/1535

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!