private void SaveKeySignButton_Click(object sender, EventArgs e) { // Save Key try { // Fetch ingredients for private key BigInteger p = BigInteger.Parse(pSignTextBox.Text); BigInteger g = BigInteger.Parse(gSignTextBox.Text); BigInteger x = BigInteger.Parse(xSignTextBox.Text); // Generate key Key k = new Key(p, g, x); Key.PrivateKey pri = k.GeneratePrivateKey(); Key.PublicKey pub = k.GeneratePublicKey(); SaveFileDialog fileBrowser = new SaveFileDialog(); DialogResult result = fileBrowser.ShowDialog(); if (result == DialogResult.OK) { string fileName = fileBrowser.FileName; k.saveToFile(fileName); } } catch (Exception ex) { //ShowMessageBox("Key generation failed."); } }
private void RandomKeySignButton_Click(object sender, EventArgs e) { // Generate Random Key key = Key.GenerateRandomKey(); Key.PrivateKey pKey = key.GeneratePrivateKey(); pSignTextBox.Text = pKey.P.ToString(); gSignTextBox.Text = pKey.G.ToString(); xSignTextBox.Text = pKey.X.ToString(); }
private void LoadKeySignButton_Click(object sender, EventArgs e) { // Load Key Sign string fileKey = ShowOpenDialog("Public Key (*.pri)|*.pri"); if (fileKey == null) { return; } Key.PrivateKey prkey = Key.GeneratePrivateKeyFromFile(fileKey); gSignTextBox.Text = prkey.G.ToString(); pSignTextBox.Text = prkey.P.ToString(); xSignTextBox.Text = prkey.X.ToString(); }
private void SignEmail(Key.PrivateKey key) { Outlook.Application application = Globals.ThisAddIn.Application; Outlook.Inspector inspector = application.ActiveInspector(); Outlook.MailItem item = (Outlook.MailItem)inspector.CurrentItem; //Outlook.MailItem item = Outlook. Inspector.CurrentItem as Outlook.MailItem; if (item != null) { string body = item.Body; item.Body = body; // Put Algorithm Sign Here SHA256 sha = new SHA256(); BigInteger hash = sha.GetMessageDigestToBigInteger(body); //System.Windows.Forms.MessageBox.Show("Hash=" + sha.GetMessageDigestToBigInteger(item.Body).ToString()); item.Body += "<sign>" + SiGamalGenerator.signature(key.P, key.G, key.X, hash) + "<sign>"; } }