Starting with PHP 5.6, you can use openssl_x509_fingerprint() :
$cert = openssl_x509_read($certificate); $sha1_hash = openssl_x509_fingerprint($cert); // sha1 hash $md5_hash = openssl_x509_fingerprint($cert, 'md5'); // md5 hash
The feature is currently undocumented, but it will be fixed at release time; this is the function signature:
openssl_x509_fingerprint($cert [, $hash_method = "sha1" [, $raw_output = false ] ] )
source share