如何从PHP路径中读取证书的指纹
问题描述:
我有证书,我希望从文件路径中读取SHA 1 Fingerprint
和SHA 256 Fingerprint
。如何从PHP路径中读取证书的指纹
<?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
?>
注:
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
请帮助我如何读取该文件,并得到指纹:我从网站上https://www.bbminfo.com/Tutor/php_error_error_log.php
我得到了一个下面的PHP警告下载的SSL证书。我正在使用PHP 7.0
答
传递给OpenSSL函数的文件路径需要是完全限定的URL。在本地文件系统上时,这意味着它们的格式为file://absolute/path/to/file
。
或者你的情况:
$certificate = "file://".realpath("./wwwbbminfocom.crt");
当然,作为意见提出,你也可以将原始文件的内容,但是这在技术上效率较低。
阅读在这里:https://secure.php.net/manual/en/openssl.certparams.php
尝试添加该文件的内容,而不是加时赛的路径:'$证书= openssl_x509_read(的file_get_contents($证书));' –
@MagnusEriksson - 非常感谢......它加工... –