简体   繁体   English

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

[英]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.

相关问题 如何在php中使用openssl提取正确格式的公钥? - How to extract public key in proper format using openssl in php? 在php中将openssl密钥转换为rsa公钥 - Convert openssl key to rsa public key in php 如何使用 openssl 和 rsa 将此 python 加密函数(aes,rsa 公钥)传输到 php? - how do I transfer this python encrypt functions (aes, rsa public key) to php with openssl and rsa? 使用字符串公钥的PHP OpenSSL公钥加密 - PHP OpenSSL Public Key Encryption With String Public Key php openssl_public_encrypt():密钥参数不是有效的公钥 - php openssl_public_encrypt(): key parameter is not a valid public key 使用PHP OpenSSL公钥将C#RSA加密转换为PHP解密 - C# RSA Encryption to PHP Decryption using PHP OpenSSL public key PHP openssl_public_encrypt“密钥参数不是有效密钥” - PHP openssl_public_encrypt “key parameter is not a valid key” PHP openssl_public_encrypt“密钥参数不是有效密钥” - PHP openssl_public_encrypt "key parameter is not a valid key" ECDSA:将 60 字节的二进制公钥转换为 PEM 格式,以便与 PHP openssl_verify() 一起使用 - ECDSA: Convert a binary public key of 60 bytes into PEM format for using it with PHP openssl_verify() openssl在php和c上获得了不同的DH公钥 - openssl got different DH public key on php and c
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM