次のコードは、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);