jproulx / crypto-js

Automatically exported from code.google.com/p/crypto-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CryptoJS.TripleDES.decrypt doesn't decrypt back

GoogleCodeExporter opened this issue · comments

1) first encrypt test_string string '12345'

 var test_string = '12345';

        var encrypt = CryptoJS.TripleDES.encrypt(
            test_string,
            key,
            { iv: iv,
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.Pkcs7
            });

        alert(encrypt);

Results: 'M4fsRZphPkk='

2) decrypt back encrypted string:

        decrypt = CryptoJS.TripleDES.decrypt(
            encrypt,
            key,
            { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });

        alert(decrypt);

yields different result: '3132333435' opposed to '12345'

Any ideas?

Note - both key and iv are initialised as per:

     var key = CryptoJS.enc.Hex.parse('a267eaaf8e5712eceb1d6d65da431ca8');
     var iv = CryptoJS.enc.Hex.parse('7b1f4e0c004c91bb ');


many thanks!


Original issue reported on code.google.com by evg...@gmail.com on 17 Feb 2013 at 8:47

The result you're seeing is 12345 in hex. You'll have to do:

    alert( decrypted.toString(CryptoJS.enc.Latin1) );


Original comment by Jeff.Mott.OR on 17 Feb 2013 at 9:24

  • Changed state: Invalid
legend, my bad...

Original comment by evg...@gmail.com on 17 Feb 2013 at 9:35