I have this test code in php:
function genPGP() {
// Create the keypair
$res=openssl_pkey_new();
// Get private key
openssl_pkey_export($res, $prK, bin2hex(mcrypt_create_iv(100, MCRYPT_DEV_URANDOM)));
// Get public key
$puK = openssl_pkey_get_public($prK);
return array($prK,$puK);
}
function prKeyDecrypt($data,$key){
if (openssl_private_decrypt($data, $r, $key)) {
return $r;
}
}
$keys = genPGP();
$prK = $keys[0];
$puK = $keys[1];
$data = 'abc123';
openssl_public_encrypt($data,$encrypted,$puK);
echo prKeyDecrypt($encrypted,$prK);
I'm getting two errors, both of them similar, and they are:
Warning: openssl_public_encrypt(): key parameter is not a valid public key in test2.php on line 23
Warning: openssl_private_decrypt(): key parameter is not a valid private key in test2.php on line 14
I'm not sure what constitutes a "valid ... key." Is there a different way I'm supposed to be getting the keys? This seems accurate according to the manual and what I've read.