遇到openssl_x509_parse()函数问题

时间:2013-07-17 16:24:58

标签: php openssl certificate x509

我遇到了openssl_x509_parse()函数

的问题
$parsed_cert = openssl_x509_parse(file_get_contents('/home/my_location/aaa010101aaa__csd_01.cer'));

该函数返回false,我不确定原因。也许证书文件必须在.pem.crt

编辑: 代码还可以,但文件的格式是问题,所以我不得不将它转换为.cer原始的.crt。

2 个答案:

答案 0 :(得分:0)

看到manual page的示例后,您的代码似乎很好。问题可能在file_get_contents。

请尝试以下操作并检查文件是否有效。

$file = file_get_contents('/home/my_location/aaa010101aaa__csd_01.cer');
$parsed_cert = openssl_x509_parse($file);

现在检查文件是什么。它存在还是有效的证书文件?

答案 1 :(得分:0)

phpseclib's pure PHP X509 implementation对X.509证书的容错能力比OpenSSL更强。以下是如何使用它的示例:

<?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

相关问题