1

这个答案在这里给出了一种使用 powershell 将 pfx 转换为 snk 的方法(围绕System.Security.Cryptography方法)。

我将如何做相反的事情,将.snk文件转换为.pfx?我可以使用 读取.snk文件Get-Content,并以某种方式使用ImportCspBlob来获取X509Certificate2对象,但我不知道:

  1. 如何实例化ImportCspBlob以获取该证书对象
  2. 如何.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,而是一些基本的对称密钥材料,密码加密。不过,我会留下这个问题,以防答案对其他人有用。

4

0 回答 0