So, why would it work in this example but not between a client and server script.
Code: Select all
<?PHP
$string = "one two three five";
$secret_key = "This is my sEcrEt key";
$len= strlen($string);
// Encryption Algorithm
$etype = MCRYPT_RIJNDAEL_256;
// Create the initialization vector for added security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size($etype, MCRYPT_MODE_ECB), MCRYPT_RAND);
// Output original string
PRINT "Original string: $string <p>";
// Encrypt $string
$encrypted_string = mcrypt_encrypt($etype, $secret_key, $string, MCRYPT_MODE_CBC, $iv);
// Convert to hexadecimal and send to browser
PRINT "Encrypted string: ".BIN2HEX($encrypted_string)."<p>";
$decrypted_string = mcrypt_decrypt($etype, $secret_key, $encrypted_string, MCRYPT_MODE_CBC, $iv);
$decrypted_string= substr($decrypted_string,0,$len);
PRINT "Decrypted string is: $decrypted_string <br/><br/>";
?>Code: Select all
$secret_key = "This is my sEcrEt key";
$etype = MCRYPT_RIJNDAEL_256;
// Create the initialization vector for added security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size($etype, MCRYPT_MODE_ECB), MCRYPT_RAND);
$input = file_get_contents("php://input");// encrypted string sent from client for vowel removal
// decrypt the input
$plainText= mcrypt_decrypt($etype, $secret_key, $input, MCRYPT_MODE_CBC, $iv);// decrypt it
$noVowels=deVowel($plainText); // remove the vowels
file_put_contents("php://output", $noVowels); //send it back
function deVowel($s) {
trim ($s);
$vowels= array("a","e","i","o","u");
return str_replace($vowels,"",$s);
}
p.s. the php encoded has been enabled on the server and it does support the type being used.
thanks for any help