DES and 3DES work only on alphabets
Opened this issue · 0 comments
GoogleCodeExporter commented
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