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 3D多模态医疗数据集-视觉问答
  • ¥20 设计一个二极管稳压值检测电路
  • ¥15 内网办公电脑进行向日葵
  • ¥15 如何输入双曲线的参数a然后画出双曲线?我输入处理函数加上后就没有用了,不知道怎么回事去掉后双曲线可以画出来
  • ¥50 WPF Lidgren.Network.Core2连接问题
  • ¥15 soildworks装配体的尺寸问题
  • ¥100 有偿寻云闪付SDK转URL技术
  • ¥30 基于信创PC发布的QT应用如何跨用户启动后输入中文
  • ¥20 非root手机,如何精准控制手机流量消耗的大小,如20M
  • ¥15 远程安装一下vasp