Question:
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?
Answer:
To retrieve the public key from a PFX certificate using Powershell, use the following command:
1 2 |
(Get-PfxCertificate -FilePath mycert.pfx).GetPublicKey() |
To convert the public key to a hex string without hyphens you can use this command:
1 2 |
[System.BitConverter]::ToString((Get-PfxCertificate -FilePath mycert.pfx).GetPublicKey()).Replace("-", "") |