Reputation: 14581
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:
ImportCspBlob
to get that certificate object.pfx
from that objectFor 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