public static bool TryUnlock(Certificate certificate) { if (certificate.PrivateKeyStatus == PrivateKeyStatus.Encrypted) { bool unlocked = false; while (!unlocked) { DecryptCaKeyDialog dialog = new DecryptCaKeyDialog(); dialog.caIdTextBox.Text = certificate.Id.ToString(); dialog.caNameTextBox.Text = certificate.FullName; if (dialog.ShowDialog() == DialogResult.OK) { try { certificate.Unlock(dialog.passphraseTextBox.Text); unlocked = true; } catch { } } else { break; } } return unlocked; } else if (certificate.PrivateKeyStatus == PrivateKeyStatus.Unavailable) { return false; } else { return true; } }
public static bool TryDecryptIfNessecary(Certificate certificate, string actionName) { if (certificate.PrivateKeyStatus == PrivateKeyStatus.Encrypted) { bool unlocked = false; string message = null; while (!unlocked) { string passphrase = ShowSetPassphrase(certificate.Id.ToString(), certificate.TypeText, actionName, message); if (passphrase.IsNullOrEmpty()) break; try { certificate.Unlock(passphrase); unlocked = true; } catch { message = GuiResources.EncryptPrivateKeyWrongPassphrase; } } return unlocked; } else if (certificate.PrivateKeyStatus == PrivateKeyStatus.Unavailable) { return false; } else { return true; } }