bwrega / crypto-js

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

DES and 3DES work only on alphabets #128

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Please use this code to produce this bug. I am trying to encrypt from PHP and 
decryption in Javascript.

PHP
function encryptByDES($plain_text,$key){
            return base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, $plain_text, MCRYPT_MODE_ECB));
        }

echo encryptByDES(json_encode(new array('type'=>'error','message'=>'Invalid 
Number. Please try another number')),'fecb4521');

JAVASCRIPT
function decryptByDES(ciphertext, key) {
var keyHex = CryptoJS.enc.Utf8.parse(key);

// direct decrypt ciphertext
var decrypted = CryptoJS.DES.decrypt({
    ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
}, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});

return decrypted.toString(CryptoJS.enc.Utf8);
}

alert(decryptByDES('<output from PHP FUNCTION ABOVE>','fecb4521'));

Original issue reported on code.google.com by haris.ah...@gmail.com on 18 Apr 2014 at 11:34