Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
CryptoJS AES decryption gives wrong result when using same parameter used on encryption

Given this code:

var s = "125\xb5\xb5$8"
/* var s = "AAAA" */
var key = CryptoJS.enc.Utf8.parse(s)
var iv = CryptoJS.enc.Utf8.parse(s)

var plain = "Very secret message!"

var encrypted = CryptoJS.AES.encrypt(plain, key, {
  keySize: 16,
  iv: iv,
  mode: CryptoJS.mode.CBC,
  padding: CryptoJS.pad.Pkcs7
});
var encryptedb64 = encrypted.toString()
console.log("encrypted:", encryptedb64)

var decrypted = CryptoJS.AES.decrypt(encryptedb64, key, {
  keySize: 16,
  iv: iv,
  mode: CryptoJS.mode.CBC,
  padding: CryptoJS.pad.Pkcs7
});

console.log("decrypted:", decrypted.toString(CryptoJS.enc.Utf8))
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>

I get this output (not expected):

"encrypted:", "W2dFmOY22wp2W1ayCa1xmk3EwaxG/H+LKkgnADKAYmY="
"decrypted:", ""

When changing the key to "AAAA" I get this output (as expected):

"encrypted:", "OAmNRtxYfJIFEq4VK4xPievfuXIIfEV+48yHBqVexWI="
"decrypted:", "Very secret message!"

I understand that key & iv should NOT be the same and should NOT be static, but that's not the point here.

I already have strings encrypted with those parameters and need to decrypt them. I expected this to work. If the encryption is giving me back a result, then decryption should work when using the same parameters.

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda