henryw4k / crypto-js

Automatically exported from code.google.com/p/crypto-js
1 stars 0 forks source link

Problem with decrypt AES #54

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi i'm trying to encrypt a social security number with a pin code and i want to 
decrypt it agian with the pin code i do my encryption like this.

var salt = CryptoJS.lib.WordArray.random(128 / 8);
                    var key = CryptoJS.PBKDF2("pin", salt, { keySize: 128 / 32, iterations: 4 });
                    var iv = CryptoJS.PBKDF2("pin", salt, { keySize: 128 / 32, iterations: 4 });

                    var a = CryptoJS.AES.encrypt("1234567890", key, { 'iv': iv });

I tryed diffent approaches to decrypt without any luck. How do i decrypt it 
agian and.

Thanks
Anders

What version of the product are you using? On what operating system?
CryptoJS 3.0.2

Original issue reported on code.google.com by mikkelse...@gmail.com on 12 Oct 2012 at 12:18

GoogleCodeExporter commented 8 years ago
Why does CryptoJS.AES.decrypt(a, key, { 'iv': iv }); not work?

Original comment by Jeff.Mott.OR on 12 Oct 2012 at 2:08

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
In this example when i call decrypt like this.

var decrypt = CryptoJS.AES.decrypt(a, key, { 'iv': iv });
var ddd = decrypt.toString(); 

I get this returned "31323334353637383930" how do i convert this back to 
"1234567890".

Original comment by mikkelse...@gmail.com on 12 Oct 2012 at 3:17

GoogleCodeExporter commented 8 years ago
CryptoJS doesn't know what kind of data you have, so its default is to output 
hex. You can tell it instead to use UTF-8.

decrypt.toString( CryptoJS.enc.Utf8 );

Original comment by Jeff.Mott.OR on 12 Oct 2012 at 4:58

GoogleCodeExporter commented 8 years ago
Thank you very much, that worked like a charm.

Original comment by mikkelse...@gmail.com on 13 Oct 2012 at 1:39

GoogleCodeExporter commented 8 years ago

Original comment by Jeff.Mott.OR on 13 Oct 2012 at 5:42