public static class CryptoHelper
{
#region 加密/解密的主要算法
private static readonly Byte[] _KeyByte = { 81, 1, 132, 230, 34, 29, 50, 200 };
private static readonly Byte[] _IVByte = { 84, 41, 32, 50, 93, 47, 4, 154 };
/// <summary>
/// 字符串加密
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static string EncryptString(string input)
{
DESCryptoServiceProvider csp = new DESCryptoServiceProvider();
ICryptoTransform ct = csp.CreateEncryptor(_KeyByte, _IVByte);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
byte[] byt = Encoding.UTF8.GetBytes(input);
cs.Write(byt, 0, byt.Length);
cs.FlushFinalBlock();
cs.Close();
return Convert.ToBase64String(ms.ToArray());
}
/// <summary>
/// 字符串解密
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static string DecryptString(string input)
{
DESCryptoServiceProvider csp = new DESCryptoServiceProvider();
ICryptoTransform ct = csp.CreateDecryptor(_KeyByte, _IVByte);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
byte[] byt = Convert.FromBase64String(input);
cs.Write(byt, 0, byt.Length);
cs.FlushFinalBlock();
cs.Close();
return Encoding.UTF8.GetString(ms.ToArray());
}
#endregion
}
转载于:https://www.cnblogs.com/miao-park/archive/2012/11/28/2793088.html
最后
以上就是悲凉铅笔最近收集整理的关于加密,解密的全部内容,更多相关加密内容请搜索靠谱客的其他文章。
发表评论 取消回复