示例#1
0
        private void btnCrypt_Click(object sender, EventArgs e)
        {
            if (tbEncodeFile.Text == "")
            {
                tbEncodeFile.Text = tbSorceFile.Text + ".encode";
            }

            PermCounter Counter = new PermCounter();

            Counter.Start();
            RSACrypt.Encode(tbSorceFile.Text, tbEncodeFile.Text, new RSAKey(Convert.ToInt64(tbKey1.Text), Convert.ToInt64(tbModule.Text)));
            tbEncodeTime.Text = Counter.Finish().ToString("F03");

            MessageBox.Show("File successfully encoded");
        }
示例#2
0
        private void btnRandSeed_Click(object sender, EventArgs e)
        {
            /*Random Rand = new Random();
             * tbKey.Text = Convert.ToString((ulong)Rand.Next() + ((ulong)(Rand.Next()) << 32));*/
            RSACrypt Rsa = new RSACrypt();

            Rsa.GenerateNewKeys();
            tbKey1.Text   = Convert.ToString(Rsa.E);
            tbKey2.Text   = Convert.ToString(Rsa.D);
            tbModule.Text = Convert.ToString(Rsa.N);

            RSACrypt Crypt = new RSACrypt();

            Crypt.GenerateNewKeys();
        }
示例#3
0
        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            if (tbDecodeFile.Text == "")
            {
                string str  = tbEncodeFile.Text;
                int    ind1 = str.LastIndexOf('.');
                int    ind2 = str.LastIndexOf('.', ind1 - 1);
                tbDecodeFile.Text = tbEncodeFile.Text + str.Substring(ind2, ind1 - ind2);
            }
            PermCounter Counter = new PermCounter();

            Counter.Start();
            RSACrypt.Decode(tbEncodeFile.Text, tbDecodeFile.Text, new RSAKey(Convert.ToInt64(tbKey2.Text), Convert.ToInt64(tbModule.Text)));
            tbDecodeTime.Text = Counter.Finish().ToString("F03");

            StreamReader Reader = new StreamReader(tbSorceFile.Text);

            byte[] OrigArray = new byte[Reader.BaseStream.Length];
            Reader.BaseStream.Read(OrigArray, 0, (int)Reader.BaseStream.Length);
            Reader.Close();
            Reader = new StreamReader(tbDecodeFile.Text);
            byte[] DecodeArray = new byte[Reader.BaseStream.Length];
            Reader.BaseStream.Read(DecodeArray, 0, (int)Reader.BaseStream.Length);
            Reader.Close();

            OrigArray   = SHA1.Create().ComputeHash(OrigArray);
            DecodeArray = SHA1.Create().ComputeHash(DecodeArray);
            if (OrigArray.SequenceEqual(DecodeArray))
            {
                MessageBox.Show("Original and decoded files identical!!! Decoding success");
            }
            else
            {
                MessageBox.Show("Original and decoded files are not identical. Decoding fail");
            }
        }