我在與openssl_x509_parse()函數經與openssl_x509_parse()函數
$parsed_cert = openssl_x509_parse(file_get_contents('/home/my_location/aaa010101aaa__csd_01.cer'));
函數返回一個錯誤,我不能確定的原因煩。也許證書文件必須在.pem
或.crt
?
編輯: 代碼是好的,但文件的格式是問題,所以我不得不將其轉換成.cer原始.crt文件的格式。
我在與openssl_x509_parse()函數經與openssl_x509_parse()函數
$parsed_cert = openssl_x509_parse(file_get_contents('/home/my_location/aaa010101aaa__csd_01.cer'));
函數返回一個錯誤,我不能確定的原因煩。也許證書文件必須在.pem
或.crt
?
編輯: 代碼是好的,但文件的格式是問題,所以我不得不將其轉換成.cer原始.crt文件的格式。
看到manual page的例子後,你的代碼看起來很好。問題可能在file_get_contents中。
請嘗試以下操作並檢查文件是否有效。
$file = file_get_contents('/home/my_location/aaa010101aaa__csd_01.cer');
$parsed_cert = openssl_x509_parse($file);
現在檢查文件是什麼。它是否存在或有效的證書文件?
phpseclib's pure PHP X509 implementation比OpenSSL更容錯X.509證書。這裏有一個如何使用它的一個例子:
<?php
include('File/X509.php');
$x509 = new File_X509();
$cert = $x509->loadX509('...'); // see google.crt
print_r($cert);
?>
至於OpenSSL的是少容錯......一個例子是如何OpenSSL won't decode keys whose individual lines are longer than 64 bytes whereas phpseclib will。