Jump to content

Encryption in Javascript/Decryption in PHP


adrek

Recommended Posts

Hi,

 

Im trying to make an application that encrypts a string using the implementation of javascript and i need this string to be decrypted using the php mcrypt module. I know that client side encryption is not secure at all but unfortunately my script requires it. The problem that i am having is that i am getting two different outputs when using slowAES and mcrypt. I am using CBC mode. Can anyone help me out.?

Thanks!

 

 

this is how I cam calling slowAES.

var cipher = slowAES.encrypt(cryptoHelpers.convertStringToByteArray("asdf"), 2, cryptoHelpers.toNumbers(stringToHex("1234567890987654")), 16, cryptoHelpers.toNumbers(stringToHex("1234567890987654")));

 

here is the PHP code

 

function base16Encode($arg){
$ret="";
for($i=0;$i<strlen($arg);$i++){
	$tmp=ord(substr($arg,$i,1));	
	$ret.=dechex($tmp);	
}
return $ret;
}

$key="1234567890987654";
$transmitKey=base16Encode($key);
$link="asdf";
$cp = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', 'cbc', '');
@mcrypt_generic_init($cp, $key,$key);
$enc = mcrypt_generic($cp, $link);   
mcrypt_generic_deinit($cp);	
mcrypt_module_close($cp);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.