以下PHP代码打印出此警告:
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
码:
$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);注意:第一个$ publicKey(第49行)是空的,第二个$ publicKey(第53行)的布尔值为“false”
我的代码有什么问题?