- #region MD5加密
-
-
-
-
-
- public static string Md5Encrypt(string strSource)
- {
-
- byte[] bytIn = System.Text.Encoding.Default.GetBytes(strSource);
-
- byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 };
- byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 };
-
- DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider();
- mobjCryptoService.Key = iv;
- mobjCryptoService.IV = key;
- ICryptoTransform encrypto = mobjCryptoService.CreateEncryptor();
-
- System.IO.MemoryStream ms = new System.IO.MemoryStream();
- CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
- cs.Write(bytIn, 0, bytIn.Length);
- cs.FlushFinalBlock();
- return System.Convert.ToBase64String(ms.ToArray());
- }
- #endregion
-
- #region MD5解密
-
-
-
-
-
- public static string Md5Decrypt(string Source)
- {
- Source = Source.Replace(' ', '+'); //注意,IDTM=JI7W/IZIoZadVU+dCqd4WSLFVJb3mK3i 中的"+"通过地址栏传过来时,后台会解析为空格. 最好的做法是 使用、、String.Replace("+", "%2B")先将空格编码,然后再作为参数传给另一页面传递,这样页面在提取参数时才会将“%2B”解码为加号.但这儿为了简化,将空格直接还原为"+"。
-
- byte[] bytIn = System.Convert.FromBase64String(Source);
-
- byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 };
- byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 };
- DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider();
- mobjCryptoService.Key = iv;
- mobjCryptoService.IV = key;
-
- System.IO.MemoryStream ms = new System.IO.MemoryStream(bytIn, 0, bytIn.Length);
- ICryptoTransform encrypto = mobjCryptoService.CreateDecryptor();
- CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Read);
- StreamReader strd = new StreamReader(cs, Encoding.Default);
- return strd.ReadToEnd();
- }
- #endregion