Пример #1
0
        //change only allow valid chars
        private void gpgPathTextBox_TextChanged(object sender, EventArgs e)
        {
            if (Program.gpgIsValid(gpgPathTextBox.Text))
            {
                signingKeyGroupBox.Enabled = true;

                GpgListSecretKeys privateKeys = new GpgListSecretKeys();
                privateKeys.Execute();

                foreach (Key key in privateKeys.Keys)
                {
                    if (!key.IsDisabled)
                    {
                        string[] row = {
                            "0x" + key.Id.ToString().Substring(key.Id.ToString().Length - 8),
                            key.UserInfos[0].Name.ToString(),//Assuming the first value is the default and will be recognized. //Does this always exist?
                            key.UserInfos[0].Email.ToString(),//Assuming the first value is the default and will be recognized. //Does this always exist?
                            key.CreationDate.ToString(),
                            key.ExpirationDate.ToString(),
                            key.Algorithm.ToString(),
                            key.Size.ToString()
                        };

                        ListViewItem lvi = new ListViewItem(row);
                        signingKeyListView.Items.Add(lvi);
                    }
                }
                if (signingKeyListView.Items.Count > 0)
                {
                    Program.autoSizeListViewColumns(signingKeyListView);
                    signingKeyListView.Items[0].Selected = true;//not working?
                }
            }
            else
            {
                signingKeyListView.Items.Clear();
                signingKeyGroupBox.Enabled = false;
                passphraseTextBox.Text = "";

                for (int i = 0; i <= 6; i++)
                    signingKeyListView.Columns[i].Width = 60;//Do dynamically
            }
        }
Пример #2
0
        private void txtPassDetail_Leave(object sender, EventArgs e)
        {
            if (txtPassDetail.ReadOnly == false)
            {
                txtPassDetail.ReadOnly = false;
                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 = Properties.Settings.Default.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);
                    }
                }
                // match keyid
                List<GpgApi.KeyId> recipients = new List<KeyId>() { };
                foreach (var line in GPGRec)
                {
                    GpgListSecretKeys publicKeys = new GpgListSecretKeys();
                    publicKeys.Execute();
                    foreach (Key key in publicKeys.Keys)
                    {
                        if (key.UserInfos[0].Email == line.ToString())
                        {
                            recipients.Add(key.Id);
                        }
                    }
                }
                // 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;
        }
Пример #3
0
        /// <summary>
        /// Callback from recrypt, ensures the file is encrypted again with the current keys
        /// </summary>
        /// <param name="result"></param>
        /// <param name="tmpFile"></param>
        /// <param name="path"></param>
        private void DecryptCallback(GpgInterfaceResult result, string tmpFile, string path)
        {
            if (result.Status == GpgInterfaceStatus.Success)
            {
                List<KeyId> recipients = new List<KeyId>();
                foreach (var line in listBox1.Items)
                {
                    GpgListSecretKeys publicKeys = new GpgListSecretKeys();
                    publicKeys.Execute();
                    recipients.AddRange(from key in publicKeys.Keys where key.UserInfos[0].Email == line.ToString() select key.Id);
                }

                string tmpFile2 = Path.GetTempFileName();
                GpgEncrypt encrypt = new GpgEncrypt(tmpFile, tmpFile2, false, false, null, recipients, CipherAlgorithm.None);
                GpgInterfaceResult encResult = encrypt.Execute();
                this.EncryptCallback(encResult, tmpFile, tmpFile2, path);
            }
            else
            {
                // shit happened
            }
        }