javascript - Crypto-Js different output from mcrypt -



javascript - Crypto-Js different output from mcrypt -

i have js script encrypts info 'blader'. if encrypt it returns output of

js-script result

uqnorevjcc2ycvy3uknjza==

now, beingness reply base of operations comparison, wrote or rather searched equivalent script in php similar js script. confuses me logic fine , right reply different. on php script uses mcrypt, have result in

mcrypt result

hzfwfnkcamko6zjeyjbg4q==

if notice, length same means logic/modification on code did correct. have said before copied script on posts here.

here's js script think uses crypto-js

function crypto_encrypt(text) { //this js var keybase64 = cryptojs.enc.base64.parse("itu2njnhi0toc2fmzexotq=="); var iv = cryptojs.enc.base64.parse('aaaaaaaaaaaaaaaaaaaaaa=='); var encrypted = cryptojs.aes.encrypt(cryptojs.enc.utf8.parse(text), keybase64, { keysize: 128 / 8, iv: iv, mode: cryptojs.mode.cbc, padding: cryptojs.pad.pkcs7 //padding: cryptojs.pad.zeropadding }); // returns base64 encoded string. homecoming encrypted; }

and here's code found in mcrypt/mycrypt

<?php $encrypted = "blader"; $iv = "0000000000000000"; // iv_base64 js $key = hexdec("213536363361234b4e736166644c4e4d"); // key_base64 js $plaintext = mcrypt_decrypt( mcrypt_rijndael_128, $key, $encrypted, mcrypt_mode_cbc, $iv ); echo base64_encode($plaintext); ?>

now question is, tried utf8_encode upto base64_encode , decode still can't find what's wrong , i'm curios attainable or not since notice iv js-script different iv in mcryp(php) tried echo it. advice, comments , suggestion highly thanked.

peace out.

first, have utilize same key , iv in php in cryptojs, or it's not going work. did compare values of key , iv? don't match.

second, have utilize same padding on each side. did check how mcrypt pads? uses zero-padding. 2 plaintexts different, because padding part of plaintext.

finally, don't want utilize mcrypt_encrypt instead of mcrypt_decrypt here?

if match key , iv, , padding, , encrypt in php, you'll same result (i've manually padded \x0a -- 10 -- match pkcs#7 padding):

$encrypted = "blader\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a\x0a"; $iv = base64_decode('aaaaaaaaaaaaaaaaaaaaaa=='); $key = base64_decode('itu2njnhi0toc2fmzexotq=='); $plaintext = mcrypt_encrypt( mcrypt_rijndael_128, $key, $encrypted, mcrypt_mode_cbc, $iv ); echo base64_encode($plaintext); uqnorevjcc2ycvy3uknjza==

javascript php encryption

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -