//加密钥匙
private static byte[] DESKey = new byte[] { 11, 23, 93, 102, 72, 41, 18, 12 };
//解密钥匙
private static byte[] DESIV = new byte[] { 75, 158, 46, 97, 78, 57, 17, 36 };
//加密算法
public string Encode(string Encode_String)
{
DESCryptoServiceProvider objDES = new DESCryptoServiceProvider();
MemoryStream objMemoryStream = new MemoryStream();
CryptoStream objCryptoStream = new CryptoStream(objMemoryStream, objDES.CreateEncryptor(DESKey, DESIV), CryptoStreamMode.Write);
StreamWriter objStreamWriter = new StreamWriter(objCryptoStream);
objStreamWriter.Write(Encode_String);
objStreamWriter.Flush();
objCryptoStream.FlushFinalBlock();
objMemoryStream.Flush();
return Convert.ToBase64String(objMemoryStream.GetBuffer(), 0, (int)objMemoryStream.Length);
}
//解密算法
public string Decode(string Encode_String)
{
DESCryptoServiceProvider objDES = new DESCryptoServiceProvider();
byte[] Input = Convert.FromBase64String(Encode_String);
MemoryStream objMemoryStream = new MemoryStream(Input);
CryptoStream objCryptoStream = new CryptoStream(objMemoryStream, objDES.CreateDecryptor(DESKey, DESIV), CryptoStreamMode.Read);
StreamReader objStreamReader = new StreamReader(objCryptoStream);
return objStreamReader.ReadToEnd();
}