コード例 #1
0
ファイル: ThisAddIn.cs プロジェクト: andhikanugraha/sigamal
        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>";

            }
        }
コード例 #2
0
ファイル: ThisAddIn.cs プロジェクト: andhikanugraha/sigamal
        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");
                }

            }
        }