Exemplo n.º 1
0
        public static void TestEncrypt()
        {
            string str = "test";

            byte[] data = Encoding.GetEncoding("UTF-8").GetBytes(str);
            string key  = "12345678";

            byte[] results = null;
            byte[] dedata  = null;
            string destr   = string.Empty;

            /*Debugger.Log("-------------------------DES-----------------------------");
             * results = EncryptUtil.DESEncryptBytes(data, key);
             * Debugger.Log("results length:" + results.Length);
             * Debugger.Log("results:" + results.ToCustomString());
             * //StringBuilder sb = new StringBuilder();
             * //foreach (byte b in results)
             * //{
             * //    sb.AppendFormat("{0:X2}", b);
             * //}
             * //Debugger.Log("result:" + sb.ToString());
             * //string result = Encoding.Unicode.GetString(results);
             * //Debugger.Log("result:" + result);
             * dedata = EncryptUtil.DESDecryptBytes(results, key);
             * destr = Encoding.UTF8.GetString(dedata);
             * Debugger.Log("destr:" + destr);
             */
            /*Debugger.Log("-------------------------AES-----------------------------");
             * key = "1234567812345678";
             * results = EncryptUtil.AESEncryptBytes(data, key);
             * Debugger.Log("results length:" + results.Length);
             * Debugger.Log("results:" + results.ToCustomString());
             * StringBuilder sb = new StringBuilder();
             * foreach (byte b in results)
             * {
             *  sb.AppendFormat("{0:X2}", b);
             * }
             * Debugger.Log("result:" + sb.ToString());
             * //result = Encoding.Unicode.GetString(results);
             * //Debugger.Log("result:" + result);
             * dedata = EncryptUtil.AESDecryptBytes(results, key);
             * destr = Encoding.UTF8.GetString(dedata);
             * Debugger.Log("destr:" + destr);
             */
            Debugger.Log("-------------------------blow fish-----------------------------");
            key     = "12345678";
            results = EncryptUtil.BlowFishEncryptBytes(data, key);
            Debugger.Log("results length:" + results.Length);
            Debugger.Log("results:" + results.ToCustomString());
            Debugger.LogError(Convert.ToBase64String(results));
            StringBuilder sb = new StringBuilder();

            foreach (byte b in results)
            {
                sb.AppendFormat("{0:X2}", b);
            }
            Debugger.Log("result:" + sb.ToString());
            //result = Encoding.Unicode.GetString(results);
            //Debugger.Log("result:" + result);
            dedata = EncryptUtil.BlowFishDecryptBytes(results, key);
            destr  = Encoding.UTF8.GetString(dedata);
            Debugger.Log("destr:" + destr);

            Debugger.Log("-------------------------Triple DES ECB-----------------------------");
            byte[] iv = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            key = "12345678123456781234567812345678";
            byte[] keyByte = Convert.FromBase64String(key);
            results = EncryptUtil.TripleDesECBEncryptBytes(data, iv, keyByte);
            Debugger.Log("results length:" + results.Length);
            Debugger.Log("results:" + results.ToCustomString());
            //result = Encoding.Unicode.GetString(results);
            //Debugger.Log("result:" + result);
            dedata = EncryptUtil.TripleDesECBDecryptBytes(results, iv, keyByte);
            destr  = Encoding.UTF8.GetString(dedata);
            Debugger.Log("destr:" + destr);
        }