Thursday, December 30, 2010

Calculate sha1 thumbprint of ssl certificate

<?php
function sha1_thumbprint_pem($pem_file_contents)
{
    $file $pem_file_contents;
    $file preg_replace('/\-+BEGIN CERTIFICATE\-+/','',$file);
    $file preg_replace('/\-+END CERTIFICATE\-+/','',$file);
    $file trim($file);
    $file str_replacearray("\n\r","\n","\r"), ''$file);
    $bin base64_decode($file);
    return sha1($bin);
}
?>

No comments: