簡體   English   中英

讀取X.509證書2私鑰

[英]Reading an X.509 Certificate2 PrivateKey

嘗試輸出PrivateKey或PublicKey時,以下代碼失敗,並顯示以下消息。 (指紋將輸出正常。):

該進程不具有此操作所需的“ 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);

您需要向該帳戶授予“管理審核和安全日志權限”。 有關更多信息,請參見http://support.microsoft.com/kb/2000257/en-US 但是,這對於證書操作來說是很奇怪的。

在這里, 如何查看RSA密鑰容器的權限可能很重要,因為它討論了訪問私鑰需要相同的特權。

該帳戶可能具有特權,但可能需要啟用。 請參見獲取/設置注冊表ACL“ SeSecurityPrivilege”時的C#隨機異常以獲取示例代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM