X509Certificate2 提示我输入密码

X509Certificate2 prompts me for password

我已将我的私钥导出到一个 pfx 文件,我正在使用它 post 一些数据到服务器。当代码命中这一行时

X509Certificate2 cert = new X509Certificate2("C:\mycerts\dml.pfx","Passw0rd");

出现提示,要求我定义密码。我写了 2 次新密码。然后当我到达这条线时

Stream newStream = request.GetRequestStream();

再次提示我输入新定义的密码,post成功

有什么方法可以避免用户交互?

系统似乎配置为使用私钥对所有密钥进行强力保护。您应该使用组策略禁用此设置:http://blogs.technet.com/b/pki/archive/2009/06/17/what-is-a-strong-key-protection-in-windows.aspx

所以我发现我的证书有一个邪恶的加密服务提供商。使用 certutil -dump 我会得到这个

---------------- End Nesting Level 1 ----------------

Provider = CRYPTOMATHiC RSA Full Provider 1.2

Simple container name: Verify

Unique container name: Verify

ERROR: missing key association property: CERT_KEY_IDENTIFIER_PROP_ID

Cannot load key: Key does not exist. 0x8009000d (-2146893811 NTE_NO_KEY)

Encryption test FAILED

不知道为什么这很糟糕,但我设法 运行 一个修复工具,然后它会显示

---------------- End Nesting Level 1 ----------------

Provider = Microsoft Enhanced RSA and AES Cryptographic Provider

Encryption test passed

现在无需提示输入密码即可运行