I need to use openssl within my php project, so I created a test php page using openssl. However, I keep getting these errors and I am not sure why. openssl is enabled.
Warning: openssl_pkey_export() [function.openssl-pkey-export]: cannot get key from parameter 1 in C:\wamp\www\opensslsample\index.php on line 18
Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in C:\wamp\www\opensslsample\index.php on line 21
<?php
//echo phpinfo();
$privateKey = openssl_pkey_new(array(
'private_key_bits' => 1024,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
));
openssl_pkey_export($privateKey, $privkey,"123");
$pubkey=openssl_pkey_get_details($privateKey);
$pubkey=$pubkey["key"];
?>
This may help if you are on windows:
The OPENSSL should be correctly working.
Check openssl_error_string
. My guess is that your openssl.cnf file is missing or something.
Alternatively, you could use phpseclib, a pure PHP RSA implementation, to generate keys. eg.
<?php
include('Crypt/RSA.php');
$rsa = new Crypt_RSA();
extract($rsa->createKey());
echo "$privatekey<br />$publickey";
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With