Dominic Brunetti
Dominic Brunetti

Reputation: 1069

How do I pull the thumbprint out of a SSL certificate FILE (not the windows cert store)?

I understand how to get the thumbprint of a certificate that's installed to a certificate store, however I'm hoping there is a way to get that information from a certificate FILE.

So for example I'd have c:\temp\mycert.com.cer... how would I get the thumbprint from that file? Is it even possible? Google isn't being very helpful. I've been doing this in powershell as such to get this from the certificate store, but again - I need to get this info from a certificate FILE.

$certCN = mysite.com
$cert = Get-ChildItem cert:\LocalMachine\My -Recurse | 
  where {$_.subject -like "*CN=$certCN*"} | 
  where {$_.ExpiringInDays -lt "91"}
$thumbprint = $cert.thumbprint

Thank you in advance!!

Upvotes: 1

Views: 3109

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125197

Without using a third party library you can rely on x509certificate2 cryptography class of .NET framework:

$content = [System.IO.File]::ReadAllBytes("D:\mycertificate.cer")
$cer = [system.security.cryptography.x509certificates.x509certificate2]::new($content)

$cer.SignatureAlgorithm.FriendlyName
$cer.Thumbprint
$cer.Subject

Then you will receive a result like:

sha1RSA
5A6008B61ABADE6412BEE4704C2407D5DE5DAA34
C=GB, O=University College London, OU=Computer Science, CN=FTAM Service

Upvotes: 4

Related Questions