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); } }
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); } }
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); } }
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); } }