private void SaveKeys(object sender, RoutedEventArgs e)
        {
            try
            {
                // Fetch ingredients for private key
                BigInteger p = BigInteger.Parse(pTextBox.Text);
                BigInteger g = BigInteger.Parse(gTextBox.Text);
                BigInteger x = BigInteger.Parse(xTextBox.Text);

                // Generate key
                SiGamalEngine.Key            k   = new SiGamalEngine.Key(p, g, x);
                SiGamalEngine.Key.PrivateKey pri = k.GeneratePrivateKey();
                SiGamalEngine.Key.PublicKey  pub = k.GeneratePublicKey();

                SaveFileDialog fileBrowser = new SaveFileDialog();

                Nullable <bool> result = fileBrowser.ShowDialog();

                if (result == true)
                {
                    string fileName = fileBrowser.FileName;
                    k.saveToFile(fileName);
                }
            }
            catch (Exception ex)
            {
                ShowMessageBox(ex.Message);
            }
        }
Exemple #2
0
        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 GeneratePrivateKey(object sender, RoutedEventArgs e)
        {
            try
            {
                // Fetch ingredients for private key

                /*BigInteger p = BigInteger.Parse(pTextBox.Text);
                *  BigInteger g = BigInteger.Parse(gTextBox.Text);
                *  BigInteger x = BigInteger.Parse(xTextBox.Text);*/

                // Generate key
                SiGamalEngine.Key            k   = SiGamalEngine.Key.GenerateRandomKey();
                SiGamalEngine.Key.PrivateKey pri = k.GeneratePrivateKey();
                SiGamalEngine.Key.PublicKey  pub = k.GeneratePublicKey();

                xTextBox.Text = pri.X.ToString();
                yTextBox.Text = pub.Y.ToString();
                pTextBox.Text = pub.P.ToString();
                gTextBox.Text = pub.G.ToString();
            }
            catch (Exception ex)
            {
                ShowMessageBox(ex.Message);
            }
        }
Exemple #4
0
 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();
 }
Exemple #5
0
        public static Key GenerateRandomKey()
        {
            Key key = null;
            BigInteger p = 10, g, x;
            byte[] bytes;
            var rng = new RNGCryptoServiceProvider();
            while (!IsMillerRabinPrime(p))
            {
                rng = new RNGCryptoServiceProvider();
                bytes = new byte[33];
                rng.GetBytes(bytes);

                p = new BigInteger(bytes);
                if (p < 0)
                {
                    p *= -1;
                }
            }

            rng = new RNGCryptoServiceProvider();
            bytes = new byte[32];
            rng.GetBytes(bytes);

            g = new BigInteger(bytes);

            if (g < 0)
            {
                g *= -1;
            }
            g %= p;
            rng.GetBytes(bytes);

            x = new BigInteger(bytes);

            if (x < 0)
            {
                x *= -1;
            }
            x %= (p - 1);
            key = new Key(p, g, x);

            return key;
        }
Exemple #6
0
 private void SignButton_Click(object sender, EventArgs e)
 {
     isSign = true;
     key = new Key(BigInteger.Parse(pSignTextBox.Text), BigInteger.Parse(gSignTextBox.Text), BigInteger.Parse(xSignTextBox.Text));
     Close();
 }
        private void SaveKeys(object sender, RoutedEventArgs e)
        {
            try
            {
                // Fetch ingredients for private key
                BigInteger p = BigInteger.Parse(pTextBox.Text);
                BigInteger g = BigInteger.Parse(gTextBox.Text);
                BigInteger x = BigInteger.Parse(xTextBox.Text);

                // Generate key
                SiGamalEngine.Key k = new SiGamalEngine.Key(p, g, x);
                SiGamalEngine.Key.PrivateKey pri = k.GeneratePrivateKey();
                SiGamalEngine.Key.PublicKey pub = k.GeneratePublicKey();

                SaveFileDialog fileBrowser = new SaveFileDialog();

                Nullable<bool> result = fileBrowser.ShowDialog();

                if (result == true)
                {
                    string fileName = fileBrowser.FileName;
                    k.saveToFile(fileName);
                }
            }
            catch (Exception ex)
            {
                ShowMessageBox(ex.Message);
            }
        }
Exemple #8
0
        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>";

            }
        }
Exemple #9
0
        private void VerifyEmail(Key.PublicKey pubKey)
        {
            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)
            {
                // Put Algorithm Verify Here
                string rs = item.Body.Substring(item.Body.IndexOf("<sign>"));
                rs = rs.Substring(6);
                rs = rs.Substring(0, rs.IndexOf("<sign>"));
                /*System.Windows.Forms.MessageBox.Show(rs);
                System.Windows.Forms.MessageBox.Show(rs.Substring(0, rs.IndexOf('-')));
                System.Windows.Forms.MessageBox.Show(item.Body.Substring(0, item.Body.IndexOf("\n<sign>") - 1));
                */
                BigInteger r = BigInteger.Parse("0" + rs.Substring(0, rs.IndexOf('-')), System.Globalization.NumberStyles.HexNumber);
                BigInteger s = BigInteger.Parse("0" + rs.Substring(rs.IndexOf('-') + 1), System.Globalization.NumberStyles.HexNumber);
                SHA256 sha = new SHA256();
                if (SiGamalGenerator.verification(r, s, pubKey.G, sha.GetMessageDigestToBigInteger(item.Body.Substring(0, item.Body.IndexOf("\n<sign>") - 2)), pubKey.Y, pubKey.P))
                {
                    System.Windows.Forms.MessageBox.Show("TRUE : Message is Valid");
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("FALSE ; Message was edited");
                }

            }
        }