I need display in web page fingerprints of SSL Certificate. Is it possible in PHP? The function
openssl_x509_parse
doesn't return SHA1 and MD5 fingerprints. How resolve this problem? Thanks.
I think you can generate the SHA fingerprint with the following code:
$resource = openssl_x509_read($certificate);
$fingerprint = null;
$output = null;
$result = openssl_x509_export($resource, $output);
if($result !== false) {
    $output = str_replace('-----BEGIN CERTIFICATE-----', '', $output);
    $output = str_replace('-----END CERTIFICATE-----', '', $output);
    $output = base64_decode($output);
    $fingerprint = sha1($output);
}
                        Here is a better solution:
 function sha1_thumbprint($file)
 {
    $file = preg_replace('/\-+BEGIN CERTIFICATE\-+/','',$file);
    $file = preg_replace('/\-+END CERTIFICATE\-+/','',$file);
    $file = trim($file);
    $file = str_replace( array("\n\r","\n","\r"), '', $file);
    $bin = base64_decode($file);
    return sha1($bin);
 }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With