In Windows 10/11, you will need to set config path to openssl (openssl.cnf
file). You can find this file in PHP directory. If you have installed gash shell you can run:
php.exe -i | grep 'Configuration File'
In my case, I have installed PHP under C:/php/php
. Your path may be different. With in PHP check for extras/ssl/
directory. You should now see openssl.cnf
file.
$configargs = [
"config" => "C:/php/php/extras/ssl/openssl.cnf",
'private_key_bits'=> 2048,
'default_md' => "sha256",
];
// Create the keypair
$res = openssl_pkey_new($configargs);
// Get private key
openssl_pkey_export($res, $privKey,NULL,$configargs);
var_dump($privKey);
// Get public key
$publickey = openssl_pkey_get_details($res);
$publickey = $publickey["key"];
var_dump($publickey);