| | |
| | | |
| | | namespace Common |
| | | { |
| | | |
| | | public class DESEncrypt |
| | | { |
| | | public static string Encrypt(string Text) |
| | | //加密串 |
| | | //public static string encryptStr = "litianping"; |
| | | public static string encryptStr = "abcDEF123@$@"; |
| | | |
| | | public static string Encrypt(string Text) |
| | | { |
| | | return DESEncrypt.Encrypt(Text, "litianping"); |
| | | return DESEncrypt.Encrypt(Text, encryptStr ); |
| | | } |
| | | |
| | | public static string Encrypt(string Text, string sKey) |
| | | { |
| | | DESCryptoServiceProvider cryptoServiceProvider = new DESCryptoServiceProvider(); |
| | | byte[] bytes = Encoding.Default.GetBytes(Text); |
| | | cryptoServiceProvider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8)); |
| | | //c#的DES加密是key为8位 |
| | | cryptoServiceProvider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8)); |
| | | cryptoServiceProvider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8)); |
| | | MemoryStream memoryStream = new MemoryStream(); |
| | | CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, cryptoServiceProvider.CreateEncryptor(), CryptoStreamMode.Write); |
| | |
| | | |
| | | public static string Decrypt(string Text) |
| | | { |
| | | return DESEncrypt.Decrypt(Text, "litianping"); |
| | | return DESEncrypt.Decrypt(Text, encryptStr); |
| | | } |
| | | |
| | | public static string Decrypt(string Text, string sKey) |
| | |
| | | { |
| | | int num = Convert.ToInt32(Text.Substring(index * 2, 2), 16); |
| | | buffer[index] = (byte) num; |
| | | } |
| | | cryptoServiceProvider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8)); |
| | | cryptoServiceProvider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8)); |
| | | MemoryStream memoryStream = new MemoryStream(); |
| | | } |
| | | //c#的DES加密是key为8位 |
| | | cryptoServiceProvider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8)); |
| | | cryptoServiceProvider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8)); |
| | | MemoryStream memoryStream = new MemoryStream(); |
| | | CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, cryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write); |
| | | cryptoStream.Write(buffer, 0, buffer.Length); |
| | | cryptoStream.FlushFinalBlock(); |