Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the public key from a PFX certificate using Powershell?

I am trying to extract the public key from a certificate using Powershell. However, whenever I use the Powershell command Get-PfxCertificate it only outputs the Thumbprint of the certificate and not the public key. How can I get it to output the public key?

like image 215
Nathan Moinvaziri Avatar asked Dec 05 '22 17:12

Nathan Moinvaziri


1 Answers

To retrieve the public key from a PFX certificate using Powershell, use the following command:

(Get-PfxCertificate -FilePath mycert.pfx).GetPublicKey()

To convert the public key to a hex string without hyphens you can use this command:

[System.BitConverter]::ToString((Get-PfxCertificate -FilePath mycert.pfx).GetPublicKey()).Replace("-", "")
like image 172
Nathan Moinvaziri Avatar answered Apr 27 '23 01:04

Nathan Moinvaziri