Home >Backend Development >PHP Tutorial >Solution to garbled code in DER format certificate read by PHP_PHP Tutorial
This article mainly introduces the relevant information on the garbled solution of the der format certificate read by php. Friends who need it can refer to it
Problems encountered:
My project needs to use the public key of the certificate in der format and the RSA algorithm to verify the relevant signatures. PHP does not know much about the RSA algorithm. I have implementations in Java and .net languages. The PHP implementation is very useful. Hard work.
Friends’ answers:
This certificate has its own corresponding encoding. You must first find this, then read it with php and set the corresponding encoding. In addition, if you directly echo the certificate content, it is best to encode it with tags before that, otherwise it is not garbled, but your browser cannot recognize it. Also pay attention to the encoding of your php file~~
Of course, reading it directly will be garbled. The der key certificate is originally a binary-encoded or BASE64-encoded file. PHP can use the openssl_x509_parse function to parse:
?
2 3
|
$cert = file_get_contents('filename.crt');
$ssl = openssl_x509_parse($cert);
var_dump($ssl); |