Exemplo n.º 1
0
        /*        private void btn_hex_from_Click(object sender, RoutedEventArgs e)
         * {
         *
         *
         *     tbx_cipher_hex.Text = HexToAnsiiString(tbx_cipher.Text);
         *
         * }
         * private void btn_hex_Click(object sender, RoutedEventArgs e)
         * {
         *
         *
         *     tbx_cipher_hex.Text = ASCIIToHexString(tbx_cipher.Text);
         *
         * }*/


        // действие при нажатии на кнопку Расшифроваь

        private void btn_decrypt_Click(object sender, RoutedEventArgs e)
        {
            if ((tbx_key.Text.Length > 128 || tbx_key.Text.Length == 0))
            {
                MessageBox.Show("Неверный размер ключа!");
                return;
            }
            Tea t = new Tea();


            tbx_plain_ascii.Text = t.Decrypt(tbx_cipher.Text, tbx_key.Text);
        }
Exemplo n.º 2
0
 private void Btn_tea_decrypt_Click(object sender, EventArgs e)
 {
     try
     {
         byte[] key  = Frm.txt_tea_key.Text.DecodeHex();
         byte[] data = Frm.txt_tea_encrypt_data.Text.DecodeHex();
         byte[] ret  = Tea.Decrypt(data, key);
         if (ret != null)
         {
             Frm.txt_tea_decrypt_data.Text = ret.HexDump();
         }
     }
     catch (Exception)
     {
         // ignored
     }
 }
Exemplo n.º 3
0
        private static void 加密解密测试()
        {
            Console.WriteLine("--------加密解密测试---------");

            string key, pwd;

            key = KeyGen.GenerateRandomKey();
            key = KeyGen.GenerateAesKey();
            key = KeyGen.GenerateDesKey();
            key = KeyGen.GenerateTeaKey();

            key = "_elong.tech@2020_"; // 自己指定Key
            pwd = "hello12345你好";

            var p1 = Aes.Encrypt(pwd, key);
            var p2 = Aes.Decrypt(p1, key);

            Console.WriteLine($"Aes加密: {p1}, Aes解密: {p2}");

            var p3 = Rc4.Encrypt(pwd, key);
            var p4 = Rc4.Decrypt(p3, key);

            Console.WriteLine($"Rc4加密: {p3}, Rc4解密: {p4}");

            var p5 = Des.Encrypt(pwd, key);
            var p6 = Des.Decrypt(p5, key);

            Console.WriteLine($"Des加密: {p5}, Des解密:{p6}");

            var p7 = Tea.Encrypt(pwd, key);
            var p8 = Tea.Decrypt(p7, key);

            Console.WriteLine($"Tea加密: {p7}, Tea解密: {p8}");

            var p9 = Hash.Md5(pwd);

            Console.WriteLine($"MD5哈希: {p9}");
            Console.WriteLine("");
        }
Exemplo n.º 4
0
 /// <summary>
 /// Decrypt data.
 /// </summary>
 public byte[] Decrypt(byte[] data, byte[] key)
 {
     return(_tea.Decrypt(data, key));
 }
Exemplo n.º 5
0
 public void Decrypt_Exception_Key_Null()
 {
     Assert.Throws <ArgumentNullException>(() => Tea.Decrypt(new byte[] { 0 }, null));
 }
Exemplo n.º 6
0
 public void Decrypt_Exception_Key_Length()
 {
     Assert.Throws <ArgumentNullException>(() => Tea.Decrypt(new byte[] { 0 }, new uint[] { 0, 1, 2 }));
 }
Exemplo n.º 7
0
 public void Decrypt_Exception_Value_Null()
 {
     Assert.Throws <ArgumentNullException>(() => Tea.Decrypt(null, new uint[] { 0 }));
 }
Exemplo n.º 8
0
 public void Decrypt_Exception_Value_Empty()
 {
     Assert.Throws <ArgumentNullException>(() => Tea.Decrypt(new byte[] { }, new uint[] { 0 }));
 }
Exemplo n.º 9
0
        public void Decrypt_Valid(byte[] value, uint[] key, byte[] encrypted)
        {
            var result = Tea.Decrypt(encrypted, key);

            Assert.True(result.SequenceEqual(value));
        }