Reputation: 39
I am working on OpenSSL in Windows 8.1, Wamp Apache Version: 2.4.9 PHP Version: 5.5.12. And I ended up with the following error:
My PHP code is given below. WAMP is unable to generate private key.
$privateKey = openssl_pkey_new(array(
'private_key_bits' => 384, // Size of Key.
'private_key_type' => OPENSSL_KEYTYPE_RSA,
));
openssl_pkey_export($privateKey, $privKey, null, ['config' => 'C:/wamp/bin/apache/apache2.4.9/conf/openssl.cnf']);
$a_key = openssl_pkey_get_details($privateKey);
file_put_contents('keys/'.$username.'_public.key', $a_key['key']);
file_put_contents('keys/'.$username.'_private.key', $privKey);
openssl_free_key($privateKey);
Can anyone please help me in running OpenSSL in Windows. Thanks in advance.
Upvotes: 1
Views: 3212
Reputation: 563
I had similiar problem and I figured out, that WAMPserver do not have default CA installed. How to fix it:
[OpenSSL-Win64]\bin\PEM\demoCA\
to c:\wamp\bin\apache\apache2.4.9\conf\demoCA\
Also make sure that OPENSSL_CONF
environmental variable is set to c:\wamp\bin\apache\apache2.4.9\conf\openssl.cnf
Upvotes: 0
Reputation: 4310
Your question isn't much specific but I can say that you're calling openssl_pkey_export
with wrong fourth argument. It should be array with config
key instead of just string. config
key is needed also for openssl_pkey_new
.
<?php
$privateKey = openssl_pkey_new([
'private_key_bits' => 384,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
'config' => 'C:/wamp/bin/apache/apache2.4.9/conf/openssl.cnf'
]);
openssl_pkey_export($privateKey, $privKey, null, [
'config' => 'C:/wamp/bin/apache/apache2.4.9/conf/openssl.cnf'
]);
$a_key = openssl_pkey_get_details($privateKey);
var_dump($privKey); // Just to test output
file_put_contents('keys/'.$username.'_public.key', $a_key['key']);
file_put_contents('keys/'.$username.'_private.key', $privKey);
openssl_free_key($privateKey);
Hope that's help
Upvotes: 3