示例#1
0
 private void btnEncryptMD52_Click(object sender, EventArgs e)
 {
     if (raBtnUTF8.Checked)
     {
         textEncryptMD5Result.Text = MyEnctypt.GetMD5(textEncryptMD5Data.Text, 1);
     }
     else if (raBtnHEX.Checked)
     {
         textEncryptMD5Result.Text = MyEnctypt.GetMD5(textEncryptMD5Data.Text, 2);
     }
 }
示例#2
0
        public static String Get3Mac(String srcStr, string key)
        {
            try
            {
                // 获取密钥
                string lKey = key.Substring(0, 16);
                string rKey = key.Substring(16, 16);

                // 初始值
                byte[] btIV = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                // 获取3DES加密后的结果
                // byte[] bys = MyTools.HexStringToBytes(srcStr);
                String strTemp = MyEnctypt.Get3DES(srcStr, key);                         // 该方法获取源数据UTF-8编码的byte,Hex编码的密钥,返回16进制字符串
                byte[] md5     = MyTools.HexStringToBytes(MyEnctypt.GetMD5(strTemp, 2)); // 获取字符串的MD5值,1为UTF-8编码,2为Hex

                byte[] bysTemp  = new byte[8];                                           // 临时数组
                byte[] bysTemp1 = new byte[8];                                           // 临时数组

                Array.Copy(md5, 0, bysTemp, 0, 8);                                       // 将md5的前8个byte拷贝到bysTemp中
                byte[] bysTemp2 = DoXOR(bysTemp, btIV);                                  // 将前8个byte和初始值求异或

                for (int i = 1; i < md5.Length / 8; i++)                                 // 轮流DES加密、异或
                {
                    Array.Copy(Encrypt(bysTemp2, lKey), 0, bysTemp, 0, 8);               // 加密
                    Array.Copy(md5, i * 8, bysTemp1, 0, 8);                              // 获取下一组
                    Array.Copy(DoXOR(bysTemp, bysTemp1), 0, bysTemp2, 0, 8);             // 异或
                }

                byte[] tail = new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                Array.Copy(Encrypt(bysTemp2, lKey), 0, bysTemp, 0, 8);  // 加密
                Array.Copy(DoXOR(bysTemp, tail), 0, bysTemp2, 0, 8);    // 异或

                Array.Copy(Encrypt(bysTemp2, lKey), 0, bysTemp, 0, 8);  // 左8个字节密钥加密
                Array.Copy(Decrypt(bysTemp, rKey), 0, bysTemp2, 0, 8);  // 右8个字节密钥解密
                Array.Copy(Encrypt(bysTemp2, lKey), 0, bysTemp, 0, 8);  // 左8个字节密钥加密

                return(MyTools.BytesToHexString(bysTemp));              // 返回16进制字符串
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "消息提示框");
            }

            return(null);
        }
示例#3
0
 private void btnEncryptTriDES2_Click(object sender, EventArgs e)
 {
     textEncryptTriDESResult.Text = MyEnctypt.Get3DES(textEncryptTriDESData.Text, textEncryptTriDESKey.Text);
 }
示例#4
0
 private void btnEncryptTriMAC2_Click(object sender, EventArgs e)
 {
     textEncryptTriMACResult.Text = MyEnctypt.Get3Mac(textEncryptTriMACData.Text, textEncryptTriMACKey.Text);
 }
示例#5
0
 private void btnEncryptDES2_Click(object sender, EventArgs e)
 {
     byte[] bys    = Encoding.UTF8.GetBytes(textEncryptDESData.Text);
     byte[] result = MyEnctypt.Encrypt(bys, textEncryptDESKey.Text);
     textEncryptDESResult.Text = MyTools.BytesToHexString(result);
 }