PHP SSL 证书序列号(十六进制)
我需要显示有关序列号的 SSL 证书信息。 当我使用时
$cert = file_get_contents('mycert.crt');
$data=openssl_x509_parse($cert,true);
$data['serialNumber']
我收到类似 -5573199485241205751 但是当我运行命令时 openssl x509 -in 'mycert.crt' -noout -serial 我收到 序列号=B2A80498A3CEDC09 可以用PHP接收吗? 谢谢。
I need to display SSL certificat information about Serial Number.
When I use
$cert = file_get_contents('mycert.crt');
$data=openssl_x509_parse($cert,true);
$data['serialNumber']
I receive like
-5573199485241205751
But when I run command
openssl x509 -in 'mycert.crt' -noout -serial
I receive
serial=B2A80498A3CEDC09
is it possible receive in PHP?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能会以字节数组形式接收序列号。将这些字节转换为十六进制,您应该获得使用 openssl 看到的序列号。
You are probably recieving the serial number as a byte array. Convert those bytes to hex and you should get the serial that you are seeing using openssl.
感谢 Petey B,这个想法很有趣,所以帮助我找到了搜索方向。
解决办法是:
Thanks Petey B the idea was interesting so have help me to find direction to search.
The solution is:
这似乎不起作用。可能是由于浮点转换。
我看到了 bcmath 的一种解决方案。
这是来自confusa的(http://www.assembla.com/code/confusa/git/nodes/lib/ca/Certificate.php?rev=a80a040c97fde2c170bb290d756c6729883fe80a):
我没有启用bcmath,所以目前无法测试它。
That doesn't seem to work. Probably due to float conversion.
I saw one solution with bcmath.
Here's from confusa (http://www.assembla.com/code/confusa/git/nodes/lib/ca/Certificate.php?rev=a80a040c97fde2c170bb290d756c6729883fe80a):
I don't have bcmath enabled so I cant test it at the moment.
您可以使用 phpseclib 来实现此目的:
You could use phpseclib for this purposes: