private void btnAdd_Click(object sender, EventArgs e) { if (txtName.Text == "") { MessageBox.Show("Name is required"); return; } byte[] secret; byte[] tokenID; byte[] privateID; StringParsing.ParseString parser; try { parser = StringParsing.GetParser((string)cboAddKeyFormat.SelectedItem); secret = parser(txtSecret.Text); if (secret.Length != 16) { MessageBox.Show("Secret must be 16-bytes"); return; } tokenID = parser(txtTokenID.Text); if (tokenID.Length != 6) { MessageBox.Show("TokenID must be 6-bytes"); return; } privateID = parser(txtPrivateID.Text); if (privateID.Length != 6) { MessageBox.Show("PrivateID must be 6-bytes"); return; } } catch { MessageBox.Show("Could not parse key(s)"); return; } int sessionCounter = 0; if (!int.TryParse(txtSessionCounter.Text, out sessionCounter)) { MessageBox.Show("Session Counter must be a valid number"); return; } if (!AddKey(txtName.Text, secret, tokenID, privateID, sessionCounter, cbPressEnter.Checked)) { MessageBox.Show("Duplicate Name"); } else { txtName.Clear(); txtSecret.Clear(); txtTokenID.Clear(); txtPrivateID.Clear(); txtSessionCounter.Text = "0"; } }
private void cboKeyFormat_SelectedIndexChanged(object sender, EventArgs e) { parser = StringParsing.GetParser((string)cboKeyFormat.SelectedItem); encoder = StringEncoding.GetEncoder((string)cboKeyFormat.SelectedItem); dataGridView1.Invalidate(); }