Long time listener/first time caller
I have set up a test page as follows
<form action="" method="post">
<input type="text" name="value" width="20" max="30" value=""/>
<input type="submit" value="go"/>
</form>
with some PHP to encrypt the post data "value" and store it in a variable like so
$pubKey = openssl_pkey_get_public(".../public.pem");
openssl_public_encrypt($_POST["value"], $var, $pubKey);
echo $var;
also have tried
$publicKey = ".../public.pem";
$plaintext = $_POST['value'];
openssl_public_encrypt($plaintext, $encrypted, $publicKey);
echo $encrypted;
Keep getting the error
Warning: openssl_public_encrypt() [function.openssl-public-encrypt]: key parameter is not a valid public key
I created the keys with openssl using:
# generate a 1024 bit rsa private key, ask for a passphrase to encrypt it and save to file
openssl genrsa -des3 -out /path/to/privatekey 1024
# generate the public key for the private key and save to file
openssl rsa -in /path/to/privatekey -pubout -out /path/to/publickey
from this website http://andytson.com/blog/2009/07/php-public-key-cryptography-using-openssl/
also tried creating a key with this method:
openssl req \
-x509 -nodes -days 365 \
-newkey rsa:1024 -keyout mycert.pem -out mycert.pem
still same error. Sorry but the whole encryption this is cryptic to me. also not very familiar with openssl so code examples would be great.