Search code examples
powershellcertificatepublic-keypkcs#12

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?


Solution

  • 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("-", "")