0

私の目的は、一意のエイリアスを外部アプリケーションに渡す必要があるため、証明書のわかりやすい名前を変更することです...私はこれを書きました:

private void button1_Click(object sender, RoutedEventArgs e)
{
   X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
   store.Open(OpenFlags.ReadWrite | OpenFlags.OpenExistingOnly);
   X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
   X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
   X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(fcollection, "Test Certificate Select", "Select a certificate from the following list to get information on that certificate", X509SelectionFlag.MultiSelection);

   foreach (X509Certificate2 x509 in scollection)
        {
            try
            {
                String originName = friendlyNameOrigin(x509);  //get orginal friendlyname
                String nameNormalized = GetHashString(normalize(friendlyNameMy(x509))); //create 'uniqualy' name as md5 code
                MessageBox.Show(x509.FriendlyName);  //showed orginal name
                x509.FriendlyName = nameNormalized;
                MessageBox.Show(x509.FriendlyName);  //showed new name
                x509.Reset();
                //next line  - I started external aplication but it still see orginal name
                //var processInfo = new ProcessStartInfo("java.exe", "-jar dist3/Signer.jar \"" + nameNormalized + "\" " + path);
                //DO SOMETHING
                //x509.FriendlyName = originName;
            }
            catch (CryptographicException)
            {
                MessageBox.Show("Information could not be written out for this certificate.");
            }
        }
        store.Close();
}

このコードはフレンドリ名を変更しますが、Windows OS にはまだ古い名前が表示されます (プログラムの実行時およびその後)。これは、フレンドリ名を設定しても、証明書のフレンドリ名が変更されないことを意味します。

証明書のフレンドリーネームを変更する方法を教えてください。

回答ありがとうございます。

4

1 に答える 1

1

解決策は、ストアを使用することです。以下のコード例:

Certificate が X509Certificate2 オブジェクトであると仮定しましょう。

Certificate.FriendlyName = "New Friendly Name";
var store = new X509Store("My");
store.Open(OpenFlags.ReadWrite);
store.Add(Certificate);
于 2013-08-27T13:39:36.947 に答える