The following PHP code prints out this warning:
Warning: openssl_csr_get_public_key(): supplied resource is not a valid OpenSSL X.509 CSR resource in /home/swissbtc/www/bitcoins.ch/index.php on line 49
Code:
$Configs = array(
'digest_alg' => 'sha1',
'x509_extensions' => 'v3_ca',
'req_extensions' => 'v3_req',
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
'encrypt_key' => true,
'encrypt_key_cipher' => OPENSSL_CIPHER_3DES
);
//generate cert
$dn = array('commonName' => 'test');
$privkey = openssl_pkey_new($Configs);
$csr = openssl_csr_new($dn, $privkey, $Configs);
$cert = openssl_csr_sign($csr, null, $privkey, 365, $Configs);
//try to get public key
$publicKey = openssl_csr_get_public_key($cert); //line 49
//try again to get the public key
openssl_x509_export($cert, $certout);
$publicKey = openssl_csr_get_public_key($certout);
Note: The first $publicKey (line 49) is empty and the second $publicKey (line 53) gets the boolean value “false”
What’s wrong with my code?
This works for me: