Well i got to encrypt certain form text with a key. i have used a button to encrypt and another to decrypt. The problem is how to assign a javascript variable to a php variable. The code is as follows:
function encryption()
{
document.encryptfrm.decryptTxt.value="";
var keyenc = document.encryptfrm.key.value;
var enc = document.encryptfrm.encryptTxt.value;
if(keyenc.length == 0)
{
alert('Please enter value for key');
document.encryptfrm.key.focus();
}
if(enc.length > 0)
{
<?php
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key ?> =keyenc;
<?php $text?> = enc;
<?php $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);?>
document.encryptfrm.decryptTxt.value=<?php echo $crypttext;?>;
document.encryptfrm.encryptTxt.value="";
}
else
{
alert('Please enter the text to be encrypted');
document.encryptfrm.encryptTxt.focus();
}
return true;
}