Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crypto-js decryption implemention #138

Open
GoogleCodeExporter opened this issue Jan 22, 2016 · 1 comment
Open

Crypto-js decryption implemention #138

GoogleCodeExporter opened this issue Jan 22, 2016 · 1 comment

Comments

@GoogleCodeExporter
Copy link

Hi, I coded 2 decryption implementations in ruby and javascript using crypto-js.
It appears the result doesn't match in both methods.

Here the implementation in ruby:


crypt_key = "6pqCt/xbHXinULTrPdMPhjGXc5IwEsIaGF9DWr0przk="
iv = "MWiW/yAGTLk2NTqK1MiZbw==\n"
data = "LbXJYXI3AFZtYfVIU47ZQ7O9S/ZgrjFGPLqCUkK13cekTFXbCil9pg/l/WCh\n91q6\n"
aes = OpenSSL::Cipher.new("AES-256-CBC")
aes.decrypt
aes.key = Base64.decode64(crypt_key)
aes.iv = Base64.decode64(iv)
final_key = aes.update(Base64.decode64(data)) + aes.final
puts "The server use this key for encryption: " + Base64.encode64(final_key)

output ======> "wPeLdB8FcAKoT9S9M3ukVRmg5AG7Aoom4GnojxogIxQ="


And in javascript with Crypto-js:

var crypt_key = 
CryptoJS.enc.Base64.parse("6pqCt/xbHXinULTrPdMPhjGXc5IwEsIaGF9DWr0przk=");
var iv = CryptoJS.enc.Base64.parse("MWiW/yAGTLk2NTqK1MiZbw==\n");
var data = 
CryptoJS.enc.Base64.parse("LbXJYXI3AFZtYfVIU47ZQ7O9S/ZgrjFGPLqCUkK13cekTFXbCil9p
g/l/WCh\n91q6\n");
var cipherParams = CryptoJS.lib.CipherParams.create({
ciphertext: data
});
var decrypted = CryptoJS.AES.decrypt(cipherParams, crypt_key, { iv: iv, mode: 
CryptoJS.mode.CBC, padding: CryptoJS.pad.NoPadding });
console.debug(decrypted.toString(CryptoJS.enc.Base64));

output ======> 
"wPeLdB8FcAKoT9S9M3ukVRmg5AG7Aoom4GnojxogIxQFnttObsTPX3OiKD/sknvaRA=="

As you can see, only the first 43 characters matches and I don't know why.

Thank you in advance for helping me.


Original issue reported on code.google.com by [email protected] on 31 Jul 2014 at 10:36

@GoogleCodeExporter
Copy link
Author

It seems that using 

    var aesDecryptor = CryptoJS.algo.AES.createDecryptor(crypt_key, { iv: iv });
    var plaintextPart1 = aesDecryptor.process(data);

give the result we expected.
I guess it has to do with the aes.final.
If someone care to explain why the result differs it would be awesome, thanks.

Original comment by [email protected] on 22 Aug 2014 at 10:50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant