private void KeySelect_Load(object sender, EventArgs e) { GpgInterface.ExePath = frmMain.cfg["GPGEXE"]; GpgListPublicKeys publicKeys = new GpgListPublicKeys(); publicKeys.Execute(); foreach (Key key in publicKeys.Keys) { comboBox1.Items.Add(key.UserInfos[0].Email + "(" + key.Id + ")"); } comboBox1.SelectedIndex= 0; this.TopMost = true; }
/// <summary> /// Cleans up and reencrypts after an edit /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TxtPassDetailLeave(object sender, EventArgs e) { if (txtPassDetail.ReadOnly == false) { txtPassDetail.ReadOnly = true; txtPassDetail.Visible = false; btnMakeVisible.Visible = true; txtPassDetail.BackColor = Color.LightGray; // read .gpg-id var gpgfile = Path.GetDirectoryName(listFileView.SelectedItem.ToString()); gpgfile += "\\.gpg-id"; // check if .gpg-id exists otherwise get the root .gpg-id if (!File.Exists(gpgfile)) { gpgfile = Cfg["PassDirectory"]; gpgfile += "\\.gpg-id"; } var gpgRec = new List<string>(); using (var r = new StreamReader(gpgfile)) { string line; while ((line = r.ReadLine()) != null) { gpgRec.Add(line.TrimEnd(' ')); } } // match keyid var recipients = new List<KeyId>(); foreach (var line in gpgRec) { var gotTheKey = false; var email = new MailAddress(line); var publicKeys = new GpgListPublicKeys(); publicKeys.Execute(); foreach (var key in publicKeys.Keys) { foreach (KeyUserInfo t in key.UserInfos) { if (t.Email == email.Address) { recipients.Add(key.Id); gotTheKey = true; } } } if (!gotTheKey) { MessageBox.Show(Strings.Error_key_missing_part1 + line + @" " + Strings.Error_key_missing_part2, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // encrypt var tmpFile = Path.GetTempFileName(); var tmpFile2 = Path.GetTempFileName(); using (var w = new StreamWriter(tmpFile)) { w.Write(txtPassDetail.Text); } var encrypt = new GpgEncrypt(tmpFile, tmpFile2, false, false, null, recipients, CipherAlgorithm.None); var encResult = encrypt.Execute(); this.EncryptCallback(encResult, tmpFile, tmpFile2, listFileView.SelectedItem.ToString()); } }
/// <summary> /// Cleans up and reencrypts after an edit /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void txtPassDetail_Leave(object sender, EventArgs e) { if (txtPassDetail.ReadOnly == false) { txtPassDetail.ReadOnly = true; txtPassDetail.Visible = false; btnMakeVisible.Visible = true; txtPassDetail.BackColor = Color.LightGray; // read .gpg-id string gpgfile = Path.GetDirectoryName(dataPass.Rows[dataPass.CurrentCell.RowIndex].Cells[0].Value.ToString()); gpgfile += "\\.gpg-id"; // check if .gpg-id exists otherwise get the root .gpg-id if (!File.Exists(gpgfile)) { gpgfile = cfg["PassDirectory"]; gpgfile += "\\.gpg-id"; } List<string> GPGRec = new List<string>() { }; using (StreamReader r = new StreamReader(gpgfile)) { string line; while ((line = r.ReadLine()) != null) { GPGRec.Add(line.TrimEnd(' ')); } } // match keyid List<GpgApi.KeyId> recipients = new List<KeyId>() { }; foreach (var line in GPGRec) { bool GotTheKey = false; MailAddress email = new MailAddress(line.ToString()); GpgListPublicKeys publicKeys = new GpgListPublicKeys(); publicKeys.Execute(); foreach (Key key in publicKeys.Keys) { for (int i = 0; i < key.UserInfos.Count; i++) { if (key.UserInfos[i].Email == email.Address) { recipients.Add(key.Id); GotTheKey = true; } } } if (!GotTheKey) { MessageBox.Show(Strings.Error_key_missing_part1 + line.ToString() + " " + Strings.Error_key_missing_part2, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // encrypt string tmpFile = Path.GetTempFileName(); string tmpFile2 = Path.GetTempFileName(); using (StreamWriter w = new StreamWriter(tmpFile)) { w.Write(txtPassDetail.Text); } GpgEncrypt encrypt = new GpgEncrypt(tmpFile, tmpFile2, false, false, null, recipients, GpgApi.CipherAlgorithm.None); GpgInterfaceResult enc_result = encrypt.Execute(); Encrypt_Callback(enc_result, tmpFile, tmpFile2, dataPass.Rows[dataPass.CurrentCell.RowIndex].Cells[0].Value.ToString()); } dataPass.Enabled = true; }