コード例 #1
0
ファイル: GenerateKeyForm.cs プロジェクト: Svabik/AdamMil.net
  void btnGenerate_Click(object sender, EventArgs e)
  {
    string realName = txtName.Text.Trim(), email = txtEmail.Text.Trim(), comment = txtComment.Text.Trim();

    if(!PGPUI.ValidateUserId(realName, email, comment) ||
       !PGPUI.ValidateAndCheckPasswords(txtPass1, txtPass2) ||
       !ValidateKeyLength(keyType, keyLength, "primary key") ||
       !ValidateKeyLength(subkeyType, subkeyLength, "subkey"))
    {
      return;
    }

    KeyTypeAndCapability primaryType = ((KeyTypeItem)keyType.SelectedItem).Value;
    NewKeyOptions options = new NewKeyOptions();
    options.Comment         = comment;
    options.Email           = email;
    options.KeyCapabilities = primaryType.Capabilities;
    options.KeyExpiration   = keyExpiration.Enabled ? keyExpiration.Value : (DateTime?)null;
    options.KeyLength       = GetSelectedKeyLength(keyLength);
    options.Keyring         = keyring;
    options.KeyType         = primaryType.Type;
    options.Password        = txtPass1.GetText();
    options.RealName        = realName;

    if(subkeyType.SelectedIndex == 0)
    {
      options.SubkeyType = KeyType.None;
    }
    else
    {
      KeyTypeAndCapability subType = ((KeyTypeItem)subkeyType.SelectedItem).Value;
      options.SubkeyCapabilities = subType.Capabilities;
      options.SubkeyExpiration   = subkeyExpiration.Enabled ? subkeyExpiration.Value : (DateTime?)null;
      options.SubkeyLength       = GetSelectedKeyLength(subkeyLength);
      options.SubkeyType         = subType.Type;
    }

    // disable the UI controls while key generation is ongoing
    btnGenerate.Enabled = grpPrimary.Enabled = grpPassword.Enabled = grpSubkey.Enabled =
      grpUser.Enabled = false;
    btnCancel.Text = "&Cancel"; // turn the "Close" button into a "Cancel" button

    progressBar.Style = ProgressBarStyle.Marquee; // start up the "progress" bar

    // and start generating the key
    thread = new Thread(delegate()
    {
      try
      {
        PrimaryKey newKey = pgp.CreateKey(options);
        Invoke((ThreadStart)delegate { GenerationSucceeded(newKey); });
      }
      catch(ThreadAbortException) { }
      catch(Exception ex) { Invoke((ThreadStart)delegate { GenerationFailed(ex); }); }
    });

    thread.Start();
  }
コード例 #2
0
 void btnOK_Click(object sender, EventArgs e)
 {
   if(PGPUI.ValidateAndCheckPasswords(pass1, pass2)) DialogResult = DialogResult.OK;
 }