这个答案在这里给出了一种使用 powershell 将 pfx 转换为 snk 的方法(围绕System.Security.Cryptography
方法)。
我将如何做相反的事情,将.snk
文件转换为.pfx
?我可以使用 读取.snk
文件Get-Content
,并以某种方式使用ImportCspBlob
来获取X509Certificate2
对象,但我不知道:
- 如何实例化
ImportCspBlob
以获取该证书对象 - 如何
.pfx
从该对象导出
对于它的价值,我尝试实例化 anX509Certificate2
然后 run ImportCspBlob
,但构造函数失败:
$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
编辑:
@TheIncorrigible 指出了构造函数问题,现在已修复。主要问题仍然存在。
我希望空的构造函数能够工作。
更新:
我不再需要这个问题了。原来它不是文件中的公私密钥对.snk
,而是一些基本的对称密钥材料,密码加密。不过,我会留下这个问题,以防答案对其他人有用。