originalfly / crypto-js

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

CryptoJS.TripleDES.decrypt doesn't decrypt back #78

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
legend, my bad...

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