我的目标是更改证书友好名称,因为我必须将唯一别名传递给外部应用程序......我写了这个:
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 操作系统仍然看到旧名称(当程序运行时和之后)。这意味着设置友好名称不会更改证书的友好名称。
你能告诉我如何更改证书的友好名称吗?
谢谢你的回答。