Esempio n. 1
0
 private void Btn_tea_encrypt_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.Encrypt(data, key);
         if (ret != null)
         {
             Frm.txt_tea_decrypt_data.Text = ret.HexDump();
         }
     }
     catch (Exception)
     {
         // ignored
     }
 }
Esempio n. 2
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("");
        }
Esempio n. 3
0
 /// <summary>
 /// Encrypt data.
 /// </summary>
 public byte[] Encrypt(byte[] data, byte[] key)
 {
     return(_tea.Encrypt(data, key));
 }
Esempio n. 4
0
 public void Encrypt_Exception_Key_Null()
 {
     Assert.Throws <ArgumentNullException>(() => Tea.Encrypt(new byte[] { 0 }, null));
 }
Esempio n. 5
0
 public void Encrypt_Exception_Key_Length()
 {
     Assert.Throws <ArgumentNullException>(() => Tea.Encrypt(new byte[] { 0 }, new uint[] { 0, 1, 2 }));
 }
Esempio n. 6
0
 public void Encrypt_Exception_Value_Null()
 {
     Assert.Throws <ArgumentNullException>(() => Tea.Encrypt(null, new uint[] { 0 }));
 }
Esempio n. 7
0
 public void Encrypt_Exception_Value_Empty()
 {
     Assert.Throws <ArgumentNullException>(() => Tea.Encrypt(new byte[] { }, new uint[] { 0 }));
 }
Esempio n. 8
0
        public void Encrypt_Valid(byte[] value, uint[] key, byte[] expected)
        {
            var result = Tea.Encrypt(value, key);

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