php读取der格式证书乱码解决方法_php实例

WBOY
Release: 2016-06-07 17:12:32
Original
955 people have browsed it

遇到的问题:

我的项目需要用到应用der格式的证书公钥及RSA算法来验签相关签名,PHP关于RSA算法不是很懂,手头上有Java和.net两种语言的实现,PHP实现甚感吃力。

小伙伴们的解答:

这个证书有他自己相应的编码,首先要找到这个,然后在用php读,设置对应的编码就好了。另外你如果是直接echo出证书内容的话,在那之前最好用标签编码一下,否则他其实没乱码,只是你浏览器无法识别而已。还要注意你php那个文件的编码哦~~

直接读取当然是乱码了,der密钥证书本来就是二进制编码或者BASE64编码的文件,php可以用openssl_x509_parse函数来解析:

 
<&#63;php
$cert = file_get_contents('filename.crt');
$ssl = openssl_x509_parse($cert);
var_dump($ssl);
&#63;>
Copy after login

以上所述就是本文的全部内容了,希望大家能够喜欢。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!