Home > Blockchain >  PowerShell - Read Certificate Issuer using public key
PowerShell - Read Certificate Issuer using public key

Time:05-27

Could someone guide me to read the issuer from public key?

I used to do this earlier using the below piece of code.

$Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import([Convert]::FromBase64String($KeyCred.key))

But its no more working.

Getting the below error.

MethodInvocationException: Exception calling "Import" with "1" argument(s):
"X509Certificate is immutable on this platform. Use the equivalent constructor instead."

I am using PowerShell 7. Appreciate any help on this.

Thanks in advance.

CodePudding user response:

If your $KeyCred.key stores a base64-encoded string that represents the certificate (not public key), then you can use appropriate constructor like this:

$cert = [Security.Cryptography.X509Certificates.X509Certificate2]::new([Convert]::FromBase64String($KeyCred.key))
  • Related