示例#1
0
 /// <summary>
 /// Open a certificate
 /// </summary>
 private void Open(string path, string password)
 {
     certificate = null;
     try
     {
         certificate = new X509Certificate2(path, password, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
         tbInfo.Text = certificate.Thumbprint;
     }
     catch
     {
         if (password == null)
         {
             // Password needed
             using (var dialog = new PasswordDialog())
             {
                 if (dialog.ShowDialog(this) == DialogResult.OK)
                     Open(path, dialog.Password);
             }
         }
         else
         {
             MessageBox.Show("Incorrect password");
         }
     }
     finally
     {
         UpdateState();
     }
 }
示例#2
0
 /// <summary>
 /// Open a certificate file.
 /// </summary>
 /// <returns>True on success, false otherwise.</returns>
 public static bool OpenCertificate(string path, string password, out string certificateThumbprint)
 {
     try
     {
         var certificate = new X509Certificate2(path, password, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
         certificateThumbprint = certificate.Thumbprint;
         ImportCertificate(certificate);
         return(true);
     }
     catch
     {
         // Password needed
         if (password == null)
         {
             using (var dialog = new PasswordDialog())
             {
                 if (dialog.ShowDialog() == DialogResult.OK)
                 {
                     return(OpenCertificate(path, dialog.Password, out certificateThumbprint));
                 }
             }
         }
         else
         {
             MessageBox.Show("Incorrect password");
         }
         certificateThumbprint = string.Empty;
         return(false);
     }
 }
示例#3
0
 /// <summary>
 /// Open a certificate file.
 /// </summary>
 /// <returns>True on success, false otherwise.</returns>
 public static bool OpenCertificate(string path, string password, out string certificateThumbprint)
 {
     try
     {
         var certificate = new X509Certificate2(path, password, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
         certificateThumbprint = certificate.Thumbprint;
         ImportCertificate(certificate);
         return true;
     }
     catch
     {
         // Password needed
         if (password == null)
         {
             using (var dialog = new PasswordDialog())
             {
                 if (dialog.ShowDialog() == DialogResult.OK)
                 {
                     return OpenCertificate(path, dialog.Password, out certificateThumbprint);
                 }
             }
         }
         else
         {
             MessageBox.Show("Incorrect password");
         }
         certificateThumbprint = string.Empty;
         return false;
     }
 }