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); } }
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); } }
private void cmdSign_Click(object sender, System.EventArgs e) { int nIntroducerDepth = 0; try { nIntroducerDepth = Convert.ToInt32(this.txtIntroducer.Text); } catch (Exception) { MessageBox.Show("Introducer depth must be a number between 0 and 8!", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); return; } if (nIntroducerDepth < 0 || nIntroducerDepth > 8) { MessageBox.Show("Introducer depth must be a number between 0 and 8!", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); return; } if ((string)cmbUserID.SelectedItem == "") { MessageBox.Show("Please select the user ID you want to sign!", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); return; } int nType = 0; if (this.rbCasualVerification.Checked) { nType = 0x12; } if (this.rbNoVerification.Checked) { nType = 0x11; } if (this.rbPositivVerification.Checked) { nType = 0x13; } QueryPassphrase qpPassphrase = new QueryPassphrase(); qpPassphrase.ShowMultiKeyDialog(SharpPrivacy.SecretKeyRing); string strKeyID = xmlKey.GetAttribute("keyid"); ulong lSignedKeyID = UInt64.Parse(strKeyID.Substring(2), System.Globalization.NumberStyles.HexNumber); ulong lSigningKeyID = qpPassphrase.SelectedKey; string strPassphrase = qpPassphrase.Passphrase; try { SharpPrivacy.Instance.SignKey(lSignedKeyID, lSigningKeyID, this.cmbUserID.Text, nIntroducerDepth, chkExportable.Checked, nType, strPassphrase); } catch (Exception ex) { MessageBox.Show("Something went wrong signing the key: " + ex.Message, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); return; } this.bSigned = true; this.Close(); }
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); } }
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); } }