douxie0824 2017-10-03 15:13
浏览 310
已采纳

使用PHP openssl函数获取公钥长度

I'm trying to get php to report the public key length of a certificate as a representation of bits.

e.g. 1024, 2048, 4096 etc.

I've trawled though countless functions on the PHP docs for answers or a steer in the right direction. Cant for the life of me work out a function that will provide this data.

http://php.net/manual/en/ref.openssl.php

openssl_pkey_get_details() seemed like the way to go. 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. So in the format of

-----BEGIN CERTIFICATE-----
MIIGWTCCBUGgAwIBAgIKG6SqTwACAAAANzANBgkqhkiG.....etc..
-----END CERTIFICATE-----
  • 写回答

1条回答 默认 最新

  • douchuose2514 2017-10-03 15:17
    关注

    i believe this http://php.net/manual/en/function.openssl-pkey-get-details.php will solve your problem

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有卷积神经网络识别害虫的项目吗
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件