日期:2014-05-17 浏览次数:20729 次
/// <summary>
/// 加密
/// </summary>
/// <param name="encryptString">加密内容</param>
/// <param name="encryptKey">密匙,长度8位</param>
/// <returns>加密后的内容</returns>
public static string Encode(string encryptString, string encryptKey)
{
DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey);
byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbKey), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
return Convert.ToBase64String(mStream.ToArray());
}
/// <summary>
/// 解密
/// </summary>
/// <param name="decryptString">加密的内容</param>
/// <param name="decryptKey">密匙:内容加密的密匙,长度8位</param>
/// <returns>解密后的内容</returns>
public static string Decode(string decryptString, string decryptKey)
{
byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey);