AES in php and then decryption using Javascript (cryptojs)

I am looking for a way to do two-way encryption of plain text (from 5 to 6 numbers and / or characters). The trick is that I want to do encryption in php and then decrypt it using Javascript. For php, I tested using mcrypt_encode and got it working, so when I try to decrypt it using javascript (I use the Crypto-js library - http://code.google.com/p/crypto-js/ ) I don’t get the results . Here is the php code I'm using:

$key = "oijhd981727783hy18274";
$text = "1233";
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC,$iv);
echo base64_encode($crypttext);

and then here is the Javascript code that I use:

var encrypted = CryptoJS.enc.Base64.parse("LiJU5oYHXRSNsrjMtCr5o2ev7yDFGZId85gh9MEXPeg=");
var key = 'oijhd981727783hy18274';
var decrypted = CryptoJS.AES.decrypt(encrypted, key);
document.write( decrypted.toString(CryptoJS.enc.Utf8) );

As I just test, I copy / paste the output from php directly to JS and see if it will return any results, however this will not happen. Since I'm new to encryption / decryption, maybe something is missing. Any suggestions would be highly appreciated.

, , , , , javascript, php -, , Javascript ( php).

+5
3

CryptoJS:

, , IV. WordArray, . , IV.

,

var decrypted = CryptoJS.AES.decrypt(encrypted, key);

"oijhd981727783hy18274" , .

IV :

var key = CryptoJS.enc.Hex.parse('000102030405060708090a0b0c0d0e0f');
var iv  = CryptoJS.enc.Hex.parse('101112131415161718191a1b1c1d1e1f');

var encrypted = CryptoJS.AES.encrypt("Message", key, { iv: iv });
+3

. , SlowAES http://code.google.com/p/slowaes/ PHP.

. , PHP.

, . GitHub, , ...

0

All Articles