I have this RSA 2048 key in the local key.key file:
Version: GnuPG v1.4.11 (GNU/Linux)
...
...
...
How can I use it in PHP to encrypt a string to send? I am in a co-hosting environment and I cannot install GNUpg, so I decided that the included OpenSSL features are the way to go.
I tried this, but I get "... the 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;
source
share