Below is a script that I have created for the purposes of helping me understand public/private key encryption. I just want to be able to encrypt a string of characters and unlike using an MD5 Hash algorithm, be able to decrypt it again.
The following script simple submits two text box input values to itself to encrypt. I am using the default values that I have set in the HTML code.
$success recieves the boolean value 1 telling me that the openssl_public_encrypt() function has worked successfully.
Unfortunately the cryptext is exactly the same as the source text.
I have the 'extension=php_openssl.dll' line in my php.ini file uncommented
I have the libeay32.dll file in my php directory which is also specified in my path environment variable and I have also copied it to my system32 folder in my windows directory (yes I am using windows).
As far as I can tell this is all I need to have openssl enabled with PHP5.
Can someone tell me what I am doing wrong? What have I missed.
<html>
<body>
<form action = "EncryptPasswordv2simpler.php" method = "get">
<input type = "text" name = "password" value = "password">
<input type = "text" name = "publickey" value = "public">
<input type = "submit">
<input type = "reset">
</form>
<?php
$pass = $_GET['password'];
$pubkey = $_GET['publikkey'];
if ($pass == "password"){
echo "Yay, got password: $pass";
}
$crypttext = "blah";
echo "Encrypted text: $crypttext";
openssl_get_publickey($pubkey);
$success = openssl_public_encrypt($pass,$crypttext,$pubkey);
if ($success)
echo "Encrypted text: $crypttext";
?>
</body>
</html>