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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.