0
以下代码在尝试输出PrivateKey或PublicKey时失败并显示以下消息。 (指纹将输出正常。):正在读取X.509证书2私钥
该进程不具有此操作所需的'SeSecurityPrivilege'特权。
如果我以本地管理员身份运行,它将起作用。我如何解决这个问题。
fyi ..证书(pfx)受密码保护 - 但不确定如何在此代码段中指明该证书。
var certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
certStore.Open(OpenFlags.ReadOnly);
string thumbprint = "D80FB0BB6485B6A2DE647812C5AA72A8F7ABA14C";
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
thumbprint, false);
// Close the certificate store.
certStore.Close();
if (certCollection.Count == 0)
{
throw new SecurityException(string.Format(CultureInfo.InvariantCulture, "No certificate was found for thumbprint {0}", thumbprint));
}
Console.WriteLine(certCollection[0].PrivateKey);
你从哪里得到错误? – msmucker0527
在Console.WriteLine中检索PrivateKey或PublicKey属性时。然而,我能够输出Thumbrprint。我在LINQPad中测试这段代码,因为这与我在自定义WCF ServiceHost中运行相同的逻辑(减去Console.WriteLine)时得到的错误消息相同。 –