1

I want to perform the following actions from inside .NET code:

  1. Create a self-signed certificate into the store, obtain its thumbprint;
  2. Import an existing certificate file into the store. Likewise, obtain thumbprint;
  3. Configure an HTTPS port for using this certificate, as per "netsh http add sslcert". I could simply run this console command from inside my program, but it'd be nice if there was a better way.

By the way, item #3 is the reason I need the thumbprints in items #1 and #2. Is this possible?

4

1 に答える 1

2

System.Security.Cryptography.X509Certificates名前空間を見てください。

特に、X509Storeクラスは、あなたが言及していることの少なくとも 1 つを実行します: 既存の証明書をストアにインポートします。例えば

X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
try
{
 store.Open(OpenFlags.ReadWrite);
 store.Add(
     new X509Certificate2(@"Certificates\MyCertificate.pfx", "password"));
}
finally
{
 store.Close();
}

以下も参照してください。


証明書を作成する他の部分の 1 つで、私はこれを見つけました: makecert.cs: makecert clone tool ... のようなコンソール ツールを呼び出さない場合はmakecert.exe、次のようなものを実装することになる可能性があります。それ。

于 2010-12-13T19:39:25.677 に答える