下面的PHP代码打印出这样的警告:为什么我无法从PHP中的X509证书中获取公钥?
警告:openssl_csr_get_public_key():提供的资源不是/home/swissbtc/www/bitcoins.ch/index.php有效的OpenSSL的X.509 CSR资源上线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);
注:第一$公钥(49行)是EM pty和第二个$ publicKey(第53行)获取布尔值“false”
我的代码有什么问题?
这要看你的密钥文件的内容。你如何生成它/你从哪里得到它? – Raptor 2012-03-07 02:07:08
密钥和证书都在上面的代码中生成。 – Roland 2012-03-07 13:37:20