Ejemplo n.º 1
0
        void mnuKeyMenuAddID_Click(Object sender, System.EventArgs e)
        {
            if (this.tlvKeys.SelectedNodes.Count == 1)
            {
                XmlElement xmlKey = (XmlElement)this.tlvKeys.SelectedNodes[0].Tag;
                if (xmlKey.Name == "PublicKey")
                {
                    ulong      lKeyID       = UInt64.Parse(xmlKey.GetAttribute("keyid").Substring(2), System.Globalization.NumberStyles.HexNumber);
                    XmlElement xmlSecretKey = null;
                    try {
                        string      strSecretKey = SharpPrivacy.Instance.GetSecretKeyProperties(lKeyID);
                        XmlDocument xmlDoc       = new XmlDocument();
                        xmlDoc.LoadXml(strSecretKey);
                        xmlSecretKey = xmlDoc.DocumentElement;
                    } catch (Exception) {
                        MessageBox.Show("You cannot add a UserID to this key as you do not own the fitting secret key!", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                        return;
                    }

                    AddUserID auiUserID = new AddUserID(xmlKey, xmlSecretKey);
                    auiUserID.ShowDialog();
                    if (!auiUserID.IsCanceled)
                    {
                        SharpPrivacy.ReloadKeyRing();
                        this.LoadKeys();
                        this.stbStatus.Text = "UserID added";
                    }
                }
                else if (xmlKey.Name == "SecretKey")
                {
                    MessageBox.Show("You cannot add a user id to a secret key.", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                }
            }
            tlvKeys.Refresh();
        }
Ejemplo n.º 2
0
 void mnuKeyMenuDelete_Click(Object sender, System.EventArgs e)
 {
     if (this.tlvKeys.SelectedNodes.Count == 1)
     {
         XmlElement xmlKey = (XmlElement)this.tlvKeys.SelectedNodes[0].Tag;
         if (xmlKey.Name == "PublicKey")
         {
             string       strKeyID = xmlKey.GetAttribute("keyid");
             DialogResult drSure   = MessageBox.Show("Are you sure you want to delete the key with the id " + strKeyID, "Warning...", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
             if (drSure == DialogResult.Yes)
             {
                 ulong lKeyID = UInt64.Parse(strKeyID.Substring(2), System.Globalization.NumberStyles.HexNumber);
                 SharpPrivacy.Instance.RemovePublicKey(lKeyID);
                 this.tlvKeys.Nodes.Remove(this.tlvKeys.SelectedNodes[0]);
                 this.stbStatus.Text = "Keys deleted";
             }
         }
         else if (xmlKey.Name == "SecretKey")
         {
             string       strKeyID = xmlKey.GetAttribute("keyid");
             DialogResult drSure   = MessageBox.Show("Are you sure you want to delete the key with the id " + strKeyID, "Warning...", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
             if (drSure == DialogResult.Yes)
             {
                 ulong lKeyID = UInt64.Parse(strKeyID.Substring(2), System.Globalization.NumberStyles.HexNumber);
                 SharpPrivacy.Instance.RemoveSecretKey(lKeyID);
                 this.tlvKeys.Nodes.Remove(this.tlvKeys.SelectedNodes[0]);
                 this.stbStatus.Text = "Keys deleted";
             }
         }
     }
     SharpPrivacy.ReloadKeyRing();
     tlvKeys.Refresh();
 }
Ejemplo n.º 3
0
        void mnuClipboardSign_Click(Object sender, System.EventArgs e)
        {
            // Check if we have some secret keys at all.
            XmlNodeList xnlSecretKeys = SharpPrivacy.SecretKeyRing.GetElementsByTagName("SecretKey");

            if (xnlSecretKeys.Count == 0)
            {
                MessageBox.Show("You cannot sign data because you do not own a private key. Please generate a new key pair, before you sign data.", "Action not possible...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                return;
            }

            string strMessage = Clipboard.GetDataObject().GetData(DataFormats.Text).ToString();

            QueryPassphrase qpPassphrase = new QueryPassphrase();

            qpPassphrase.ShowMultiKeyDialog(SharpPrivacy.SecretKeyRing);
            ulong  lSignatureKeyID = qpPassphrase.SelectedKey;
            string strPassphrase   = qpPassphrase.Passphrase;

            try {
                SharpPrivacy.ReloadKeyRing();
                string strReturn = SharpPrivacy.Instance.SignText(strMessage, lSignatureKeyID, strPassphrase);
                Clipboard.SetDataObject(strReturn);
            } catch (Exception ex) {
                MessageBox.Show("An error occured while encrypting the message: " + ex.Message + "\n\n" + ex.StackTrace, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
        }
Ejemplo n.º 4
0
        void mnuFileSystemEncrypt_Click(Object sender, System.EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog ofdOpen = new System.Windows.Forms.OpenFileDialog();

            ofdOpen.Multiselect = true;
            ofdOpen.Filter      = "All Files (*.*)|*.*";
            ofdOpen.ShowDialog();

            if (ofdOpen.FileNames.Length == 0)
            {
                return;
            }

            PublicKeySelector pksSelector = new PublicKeySelector(SharpPrivacy.PublicKeyRing);

            pksSelector.ShowDialog();

            ulong[] lTargetKeyIDs = (ulong[])pksSelector.SelectedKeys.ToArray(Type.GetType("System.UInt64"));

            for (int i = 0; i < ofdOpen.FileNames.Length; i++)
            {
                string strPath = ofdOpen.FileNames[i];
                SharpPrivacy.ReloadKeyRing();
                SharpPrivacy.Instance.EncryptFile(strPath, strPath + ".asc", lTargetKeyIDs);
            }
        }
Ejemplo n.º 5
0
        void mnuFileSystemSign_Click(Object sender, System.EventArgs e)
        {
            // Check if we have some secret keys at all.
            XmlNodeList xnlSecretKeys = SharpPrivacy.SecretKeyRing.GetElementsByTagName("SecretKey");

            if (xnlSecretKeys.Count == 0)
            {
                MessageBox.Show("You cannot sign data because you do not own a private key. Please generate a new key pair, before you sign data.", "Action not possible...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                return;
            }

            System.Windows.Forms.OpenFileDialog ofdOpen = new System.Windows.Forms.OpenFileDialog();

            ofdOpen.Multiselect = true;
            ofdOpen.Filter      = "All Files (*.*)|*.*";
            ofdOpen.ShowDialog();

            if (ofdOpen.FileNames.Length == 0)
            {
                return;
            }

            QueryPassphrase qpPassphrase = new QueryPassphrase();

            qpPassphrase.ShowMultiKeyDialog(SharpPrivacy.SecretKeyRing);
            ulong  lSignatureKeyID = qpPassphrase.SelectedKey;
            string strPassphrase   = qpPassphrase.Passphrase;

            for (int i = 0; i < ofdOpen.FileNames.Length; i++)
            {
                string strPath = ofdOpen.FileNames[i];
                SharpPrivacy.ReloadKeyRing();
                SharpPrivacy.Instance.SignFile(strPath, strPath + ".asc", lSignatureKeyID, strPassphrase);
            }
        }
Ejemplo n.º 6
0
        private void StartKeyGeneration()
        {
            iKeySize = Convert.ToInt32(cmbKeySize.Text);
            this.pbCurrentProgress.Value = 0;
            this.timProgressBar.Start();
            this.cmdCancel.Enabled = false;
            this.cmdNext.Enabled   = false;

            iKeySize = Int32.Parse(this.cmbKeySize.Text);
            SharpPrivacy.ReloadKeyRing();
            tThread = new System.Threading.Thread(new System.Threading.ThreadStart(Start));
            tThread.Start();
            while (tThread.IsAlive)
            {
                System.Threading.Thread.Sleep(100);
                Application.DoEvents();
            }
            SharpPrivacy.ReloadKeyRing();

            panKeyGeneration.Visible = false;
            panDone.Visible          = true;
            cmdCancel.Visible        = false;
            cmdBack.Visible          = false;
            cmdNext.Enabled          = true;
            cmdNext.Text             = "Finish";

            this.lblText.Text    = "Your keypair has been created and is ready for use.";
            this.lblCaption.Text = "Key Generation is Complete";
        }
Ejemplo n.º 7
0
        void mnuKeyMenuPaste_Click(Object sender, System.EventArgs e)
        {
            string strClipboard = Clipboard.GetDataObject().GetData(DataFormats.Text).ToString();

            try {
                SharpPrivacy.Instance.AddKey(strClipboard);
            } catch (Exception ex) {
                MessageBox.Show("An error occured: " + ex.Message, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
            SharpPrivacy.ReloadKeyRing();
            this.LoadKeys();
            tlvKeys.Refresh();
        }
Ejemplo n.º 8
0
        void mnuClipboardDecryptVerify_Click(Object sender, System.EventArgs e)
        {
            string strMessage = Clipboard.GetDataObject().GetData(DataFormats.Text).ToString();

            bool  bAskForPassphrase = true;
            ulong lDecryptionKey    = 0;

            try {
                SharpPrivacy.ReloadKeyRing();
                lDecryptionKey = SharpPrivacy.Instance.GetDecryptionKey(strMessage);
            } catch (Exception ex) {
                bAskForPassphrase = false;
                Console.WriteLine(ex.Message);
            }

            string strPassphrase = "";

            if (bAskForPassphrase)
            {
                QueryPassphrase qpPassphrase = new QueryPassphrase();
                if (lDecryptionKey > 0)
                {
                    //Find the fitting key
                    XmlElement xmlKey = FindSecretKey(lDecryptionKey);
                    if (xmlKey == null)
                    {
                        MessageBox.Show("An unexpected error occured: The secret key used to decrypt the message could not be found.", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                        return;
                    }
                    qpPassphrase.ShowSingleKeyDialog(xmlKey);
                    strPassphrase = qpPassphrase.Passphrase;
                }
                else
                {
                    qpPassphrase.ShowMyDialog();
                    strPassphrase = qpPassphrase.Passphrase;
                }
            }

            try {
                PlaintextViewer pvPlaintext = new PlaintextViewer();
                SharpPrivacy.ReloadKeyRing();
                pvPlaintext.XmlMessage = SharpPrivacy.Instance.DecryptAndVerify(strMessage, strPassphrase);
                pvPlaintext.ShowPlaintext();
            } catch (Exception ex) {
                MessageBox.Show("An error occured while decrypting the message: " + ex.Message, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
        }
Ejemplo n.º 9
0
        void mnuFileSystemDecryptVerify_Click(Object sender, System.EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog ofdOpen = new System.Windows.Forms.OpenFileDialog();

            ofdOpen.Multiselect = false;
            ofdOpen.Filter      = "OpenPGP Files (*.asc;*.enc)|*.asc;*.enc|All Files (*.*)|*.*";
            ofdOpen.ShowDialog();

            bool  bAskForPassphrase = true;
            ulong lDecryptionKey    = 0;

            try {
                SharpPrivacy.ReloadKeyRing();
                lDecryptionKey = SharpPrivacy.Instance.GetDecryptionKeyFromFile(ofdOpen.FileName);
            } catch (Exception) {
                bAskForPassphrase = false;
            }

            string strPassphrase = "";

            if (bAskForPassphrase)
            {
                QueryPassphrase qpPassphrase = new QueryPassphrase();
                if (lDecryptionKey > 0)
                {
                    //Find the fitting key
                    XmlElement xmlKey = FindSecretKey(lDecryptionKey);
                    qpPassphrase.ShowSingleKeyDialog(xmlKey);
                    strPassphrase = qpPassphrase.Passphrase;
                }
                else
                {
                    qpPassphrase.ShowMyDialog();
                    strPassphrase = qpPassphrase.Passphrase;
                }
            }

            try {
                PlaintextViewer pvPlaintext = new PlaintextViewer();
                SharpPrivacy.ReloadKeyRing();
                pvPlaintext.XmlMessage = SharpPrivacy.Instance.DecryptAndVerifyFile(ofdOpen.FileName, strPassphrase);
                pvPlaintext.ShowPlaintext();
            } catch (Exception ex) {
                MessageBox.Show("An error occured while decrypting the message: " + ex.Message, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
        }
Ejemplo n.º 10
0
        void mnuClipboardEncrypt_Click(Object sender, System.EventArgs e)
        {
            string strMessage = Clipboard.GetDataObject().GetData(DataFormats.Text).ToString();

            PublicKeySelector pksSelector = new PublicKeySelector(SharpPrivacy.PublicKeyRing);

            pksSelector.ShowDialog();

            ulong[] lTargetKeyIDs = (ulong[])pksSelector.SelectedKeys.ToArray(Type.GetType("System.UInt64"));

            try {
                startWorking();
                SharpPrivacy.ReloadKeyRing();
                string strReturn = SharpPrivacy.Instance.EncryptText(strMessage, lTargetKeyIDs);
                Clipboard.SetDataObject(strReturn);
                stopWorking();
            } catch (Exception ex) {
                MessageBox.Show("An error occured while encrypting the message: " + ex.Message + "\n\n" + ex.StackTrace, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
        }
Ejemplo n.º 11
0
 void mnuKeyMenuAddSignature_Click(Object sender, System.EventArgs e)
 {
     if (this.tlvKeys.SelectedNodes.Count == 1)
     {
         XmlElement xmlKey = (XmlElement)this.tlvKeys.SelectedNodes[0].Tag;
         if (xmlKey.Name == "PublicKey")
         {
             SignKey skSign = new SignKey(xmlKey);
             skSign.ShowDialog();
             if (!skSign.IsCanceled)
             {
                 SharpPrivacy.ReloadKeyRing();
                 this.LoadKeys();
                 this.stbStatus.Text = "Key signed";
             }
         }
         else if (xmlKey.Name == "SecretKey")
         {
             MessageBox.Show("You cannot sign a secret key.", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
         }
     }
 }
Ejemplo n.º 12
0
        public SharpPrivacyTray()
        {
            DateTime     dtStart  = DateTime.Now;
            SplashScreen ssSplash = new SplashScreen();

            ssSplash.Show();
            Application.DoEvents();

            // check if private and public keyring exists
            bool   bMessageShowed = false;
            string strPath        = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            if (!System.IO.File.Exists(strPath + "/SharpPrivacy/pub_keyring.txt"))
            {
                MessageBox.Show("SharpPrivacy was unable to find a keyring. This might be due to you starting this program for the first time. A new keyring will be created in your home directory.", "Keyring...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                bMessageShowed = true;
                try {
                    System.IO.Directory.CreateDirectory(strPath + "/SharpPrivacy");
                } catch (Exception e) {
                    MessageBox.Show("Error creating the SharpPrivacy home directory:" + e.Message, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                }
                try {
                    FileStream fsTmp = System.IO.File.Create(strPath + "/SharpPrivacy/pub_keyring.txt");
                    fsTmp.Close();
                } catch (Exception e) {
                    MessageBox.Show("Error creating the public keyring file:" + e.Message, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                }
            }

            if (!System.IO.File.Exists(strPath + "/SharpPrivacy/sec_keyring.txt"))
            {
                if (!bMessageShowed)
                {
                    MessageBox.Show("SharpPrivacy was unable to find a keyring. This might be due to you starting this program for the first time. A new keyring will be created in your home directory.", "Keyring...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                }
                bMessageShowed = true;
                try {
                    FileStream fsTmp = System.IO.File.Create(strPath + "/SharpPrivacy/sec_keyring.txt");
                    fsTmp.Close();
                } catch (Exception e) {
                    MessageBox.Show("Error creating the secret keyring file:" + e.Message, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                }
            }

            SharpPrivacy.ReloadKeyRing();

            InitializeComponent();
            InitializeCustomComponents();
            this.WindowState = FormWindowState.Minimized;
            this.ResumeLayout(false);

            int iCount = 0;

            while (dtStart.AddSeconds(5) > DateTime.Now)
            {
                if (iCount % 10 == 0)
                {
                    Application.DoEvents();
                }
                iCount++;
                System.Threading.Thread.Sleep(50);
            }
            ssSplash.Hide();
        }