brix / crypto-js

JavaScript library of crypto standards.
Other
15.8k stars 2.38k forks source link

Decryption issue with Triple DES algorithm. #152

Open abhinandanpatilInd opened 6 years ago

abhinandanpatilInd commented 6 years ago

I'm doing the Triple DES encryption with below details:

  1. HEX Key : 579D2D852F2F3BABABBD71B7BD3B7D11
  2. Data to encrypt : 141234FFFFFFFF

Code I used: var encrypted = CryptoJS.TripleDES.encrypt('141234FFFFFFFF', '579D2D852F2F3BABABBD71B7BD3B7D11'); console.log("DES3 encrypted text:"+encrypted); var decrypted = CryptoJS.TripleDES.decrypt(encrypted, '579D2D852F2F3BABABBD71B7BD3B7D11'); console.log("DES3 decrypted text:"+decrypted);

Issues I'm facing:

  1. Each time I'm getting different out put of above code
  2. Decryption doesn't producing clear text which was supplied to encryption.

Any inputs on above are highly appreciated!!

ljudbane commented 6 years ago

Try encoding the decrypted result in UTF8: decrypted.toString(CryptoJS.enc.Utf8). It should give you the original string.

As for issue 1: You get different encrypted value each time because each time a new random initialization vector is generated.