概述
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
最后
以上就是悲凉铅笔为你收集整理的加密,解密的全部内容,希望文章能够帮你解决加密,解密所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复