• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

116
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.

over 2 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda