I have this RSA 2048 key on a local "key.key" file:
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.11 (GNU/Linux)
...
...
...
-----END PGP PUBLIC KEY BLOCK-----
How can I use it in PHP to encrypt a string to send? I am on a shared hosting environment and I can't install GNUpg, so I figured the included OpenSSL functions are the way to go.
I tried this, but I get "...key parameter is not a valid public key..."
<?php
$text = 'hello jeremy how are you';
$key = openssl_pkey_get_public(chunkfile_get_contents('key.key'));
openssl_public_encrypt($text, $encrypted, $key);
echo $crypted;
exit;