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)時得到的錯誤消息相同。 –