deitch
deitch

Reputation: 14581

How to convert snk to pfx using PowerShell?

This answer here gave a method for converting a pfx to snk using powershell (wrapped around the System.Security.Cryptography methods).

How would I do the reverse, convert a .snk file to .pfx? I can read the .snk file with Get-Content, and somehow use ImportCspBlob to get an X509Certificate2 object, but I do not know:

  1. How to instantiate ImportCspBlob to get that certificate object
  2. How to export a .pfx from that object

For what it's worth, I tried to instantiate an X509Certificate2 and then run ImportCspBlob, but the constructor failed:

$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2();
At line:1 char:83
+ ... ect System.Security.Cryptography.X509Certificates.X509Certificate2();
+                                                                        ~
An expression was expected after '('.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedExpression

EDIT:

@TheIncorrigible pointed out the constructor problem, which now is fixed. Main questions still remain.

I expected the empty constructor to work.

UPDATE:

I no longer have need for this question. Turns out it was not a public-private keypair in the .snk file, but rather some basic symmetric key material, password-encrypted. I will leave the question, though, in case the answer is useful to others.

Upvotes: 1

Views: 433

Answers (0)

Related Questions