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

454
Views
AES-GCM necesita el mismo init_vector del cifrado PARA el descifrado. ¿Por qué?

Creé un ejemplo de TypeScript a partir del ejemplo de MDN tan textualmente como pude para ilustrar. Cifra y descifra perfectamente. Me acabo de dar cuenta de que, para que Decryption funcione, requiere el mismo init_vector del cifrado. ¿No se supone que init_vector es un nonce?

¿Cómo va a saber la persona que recibe el mensaje cuál es el init_vector que he usado para el cifrado si el descifrado es un proceso separado realizado en un lugar y momento diferentes?

 const message_plain: string = "Hello World!"; const password_plain: string = "letmein"; // AES-GCM - ENCRYPTION const pbkdf2_salt: Uint8Array = crypto.getRandomValues(new Uint8Array(16)); // 128 bits const pbkdf2_iterations: number = 100000; const init_vector: Uint8Array = crypto.getRandomValues(new Uint8Array(12)); // 96 bits const utf8_encoder: TextEncoder = new TextEncoder(); const message_bytes: Uint8Array = utf8_encoder.encode(message_plain); const password_bytes: Uint8Array = utf8_encoder.encode(password_plain); const crypto_key_material: CryptoKey = await crypto.subtle.importKey( "raw", password_bytes, { name: "PBKDF2" }, false, ["deriveBits", "deriveKey"], ); const crypto_key_derived: CryptoKey = await crypto.subtle.deriveKey( { "name": "PBKDF2", salt: pbkdf2_salt, "iterations": pbkdf2_iterations, "hash": "SHA-256", }, crypto_key_material, { "name": "AES-GCM", "length": 256 }, true, ["encrypt", "decrypt"], ); const message_encrypted: ArrayBuffer = await crypto.subtle.encrypt( { name: "AES-GCM", iv: init_vector }, crypto_key_derived, message_bytes, ); const message_encrypted_bytes: Uint8Array = new Uint8Array(message_encrypted); console.log( `[${message_encrypted.byteLength} bytes total] -> ${message_encrypted_bytes}`, ); // AES-GCM - DECRYPTION const utf8Decoder: TextDecoder = new TextDecoder(); try { const message_decrypted: ArrayBuffer = await crypto.subtle.decrypt( { name: "AES-GCM", iv: init_vector }, crypto_key_derived, message_encrypted, ); const message_decrypted_bytes: Uint8Array = new Uint8Array(message_decrypted); console.log(utf8Decoder.decode(message_decrypted_bytes)); } catch (e) { console.log("*** Decryption error ***"); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe usar cifrado asimétrico como RSA que tiene una clave pública/privada, por ejemplo, este paquete node-rsa .

En términos de tener el mismo vector inicial, encontré este fragmento tomado de esta respuesta :

En cualquier caso, el IV nunca necesita mantenerse en secreto; si lo hiciera, sería una clave, no un IV. De hecho, en la mayoría de los casos, mantener el IV en secreto no sería práctico, incluso si quisiera, ya que el destinatario necesita saberlo para descifrar los datos (o verificar el hash, etc.).

about 4 years ago · Juan Pablo Isaza 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!