php读取证书公钥,为什么我不能用PHP中的X509证书获取公钥?

以下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”

我的代码有什么问题?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值