John Davidson

x509certificate - How to get complete Issuer Name from cert.pem in php

0 comments
Message:


I want to get the whole issuer name from cert.pem and I have this output:


Array, TSZEINVOICE-SubCA-1

the output should be like this:


CN=TSZEINVOICE-SubCA-1, DC=extgazt, DC=gov, DC=local

the code I am using :


$data = openssl_x509_parse(file_get_contents('cert.pem'));
$issuername = $data['issuer'];
echo implode(", ",$issuername);

but only I got the first is CN but cannot get DN values!



My Answer:
To get the complete issuer name from the cert.pem file in PHP, you can use the following code:

php
$data = openssl_x509_parse(file_get_contents('cert.pem'));
$issuername = $data['issuer'];
$issuerString = '';
foreach ($issuername as $key => $value) {
$issuerString .= $key . '=' . $value . ', ';
}
$issuerString = rtrim($issuerString, ', ');
echo $issuerString;


This code will iterate over the key-value pairs in the issuer array and concatenate them into a string in the format key=value, key=value, ... until all key-value pairs are processed. Finally, it will remove the trailing comma and space before echoing the complete issuer name.

Rate this post

5 of 5 based on 2705 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us