gpt4 book ai didi

php - 如何从 PHP 中的路径读取证书的指纹

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:02 24 4
gpt4 key购买 nike

我有一个证书,我希望从文件路径中读取 SHA 1 FingerprintSHA 256 Fingerprint

<?php

ini_set("display_startup_errors", 1);
ini_set("display_errors", 1);
error_reporting(-1);

$certificate = "./wwwbbminfocom.crt";
$cert = openssl_x509_read($certificate);
$sha1_hash = openssl_x509_fingerprint($cert); // sha1 hash
$md5_hash = openssl_x509_fingerprint($cert, 'md5'); // md5 hash

?>

注意:我从网站 https://www.bbminfo.com/Tutor/php_error_error_log.php 下载了 SSL 证书

我收到以下 PHP 警告:

Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in /home/super/public_html/md.php on line 8

Warning: openssl_x509_fingerprint(): cannot get cert from parameter 1 in /home/super/public_html/md.php on line 9

Warning: openssl_x509_fingerprint(): cannot get cert from parameter 1 in /home/super/public_html/md.php on line 10

请帮助我如何读取文件并获取指纹。我正在使用 PHP 7.0

最佳答案

传递给 OpenSSL 函数的文件路径需要是完全限定的 URL。在本地文件系统上时,这意味着它们采用 file://absolute/path/to/file 格式。

或者在你的情况下:

$certificate = "file://".realpath("./wwwbbminfocom.crt");

当然,正如评论中所建议的,您也可以传递原始文件内容,但这在技术上效率较低。

阅读此处:https://secure.php.net/manual/en/openssl.certparams.php

关于php - 如何从 PHP 中的路径读取证书的指纹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45464514/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com