$publicKey = "../ssh/public/pub"; $plaintext = "String to encrypt";
$pubKey = openssl_pkey_get_public($publicKey);
openssl_public_encrypt($plaintext, $encrypted, $pubKey);
echo $encrypted; //encrypted string
above code generating following error
openssl_public_encrypt() [http://php.net/function.openssl-public-encrypt]: key parameter is not a valid public key [APP/controllers/supportservice_controller.php, line 144]
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