Esempio n. 1
0
 // Allow using HMAC without bringing (most of) the whole crypto stack (using CryptoConfig)
 // or even without bringing all the hash algorithms (using a common switch)
 internal void SetHash(string name, HashAlgorithm instance)
 {
     _hashName = name;
     _algo     = instance;
 }
Esempio n. 2
0
        private void Button1_Click(object sender, EventArgs Obj)
        {
            if (comboBox1.SelectedIndex != -1)
            {
                if (CheckData())
                {
                    if (comboBox1.SelectedIndex == 0)
                    {
                        BigInteger fi = FindFuncEl(BigInteger.Parse(textBoxP.Text), BigInteger.Parse(textBoxQ.Text));
                        BigInteger d  = BigInteger.Parse(textBoxD.Text);
                        BigInteger n  = BigInteger.Parse(textBoxP.Text) * BigInteger.Parse(textBoxQ.Text);
                        textBoxR.Text = n.ToString();

                        BigInteger e, temp;
                        EuclideanAlgorithm(fi, d, out e, out temp);
                        if (e.Sign < 0)
                        {
                            e += fi;
                        }
                        textBoxE.Text = e.ToString();

                        SHA1.SHA1 sha1    = new SHA1.SHA1();
                        byte[]    hash    = sha1.ComputeHash(currentFile);
                        uint[]    decHash = ArrBytesToArrUint(hash);
                        textBoxFH.Text = ToHexString(decHash);
                        plainSignature = BigInteger.Parse("0" + ToHexString(decHash), NumberStyles.HexNumber);
                        textBoxFD.Text = plainSignature.ToString();
                        plainSignature = FastExp(plainSignature, d, n);
                    }
                    else
                    {
                        SHA1.SHA1 sha1    = new SHA1.SHA1();
                        byte[]    hash    = sha1.ComputeHash(currentFile);
                        uint[]    decHash = ArrBytesToArrUint(hash);
                        textBoxFH.Text = ToHexString(decHash);
                        plainSignature = BigInteger.Parse("0" + ToHexString(decHash), NumberStyles.HexNumber);
                        textBoxFD.Text = plainSignature.ToString();

                        if (cipherSignature == plainSignature)
                        {
                            MessageBox.Show(signatureTrue, sucsess, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        else
                        {
                            Error(signatureFalse);;
                        }
                    }
                }
                else if (currentFile == null)
                {
                    Error(errorSelectedFile);
                }
                else
                {
                    Error(invalidData);
                }
            }
            else
            {
                Error(selectAction);
            }
        }