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

174
Views
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
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!