[英]Using PHP openssl functions to get public key length
I'm trying to get php to report the public key length of a certificate as a representation of bits. 我试图让php报告证书的公钥长度作为位的表示形式。
eg 1024, 2048, 4096 etc. 例如1024、2048、4096等。
I've trawled though countless functions on the PHP docs for answers or a steer in the right direction. 我在PHP文档上拖曳了无数函数,以寻求答案或朝着正确的方向发展。 Cant for the life of me work out a function that will provide this data. 不能为我的生活制定出可以提供此数据的功能。
http://php.net/manual/en/ref.openssl.php http://php.net/manual/en/ref.openssl.php
openssl_pkey_get_details() seemed like the way to go. openssl_pkey_get_details()似乎很可行。 But cant find a way to give it the public key in the first place. 但是无法找到一种首先为其提供公钥的方法。
Currently i can parse the certificate. 目前,我可以解析证书。 However this doesn't include the public key or bits information. 但是,这不包括公钥或位信息。
<?php
$cert = $_POST['cert_text'];
$ssl = openssl_x509_parse($cert);
echo json_encode($ssl);
?>
The $cert variable above is a PEM format certificate file. 上面的$ cert变量是PEM格式的证书文件。 So in the format of 因此,格式为
-----BEGIN CERTIFICATE-----
MIIGWTCCBUGgAwIBAgIKG6SqTwACAAAANzANBgkqhkiG.....etc..
-----END CERTIFICATE-----
i believe this http://php.net/manual/en/function.openssl-pkey-get-details.php will solve your problem 我相信这个http://php.net/manual/en/function.openssl-pkey-get-details.php将解决您的问题
using 运用
array openssl_pkey_get_details ( resource $key )
Returns an array with the key details in success or FALSE in failure. 返回一个数组,其中包含成功的键详细信息或失败的错误详细信息。 Returned array has indexes bits (number of bits), key (string representation of the public key) and type (type of the key which is one of OPENSSL_KEYTYPE_RSA, OPENSSL_KEYTYPE_DSA, OPENSSL_KEYTYPE_DH, OPENSSL_KEYTYPE_EC or -1 meaning unknown). 返回的数组具有索引位(位数),密钥(公共密钥的字符串表示形式)和类型(密钥的类型,该类型为OPENSSL_KEYTYPE_RSA,OPENSSL_KEYTYPE_DSA,OPENSSL_KEYTYPE_DH,OPENSSL_KEYTYPE_EC或-1表示未知)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.