#region ========加密========

         /// <summary>
/// 加密
/// </summary>
/// <param name="Text"></param>
/// <returns></returns>
public static string Encrypt(string Text)
{
if (Text == null)
return Text;
return Encrypt(Text, "123456789abcd");
}
/// <summary>
/// 加密数据
/// </summary>
/// <param name="Text"></param>
/// <param name="sKey"></param>
/// <returns></returns>
public static string Encrypt(string Text, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray;
inputByteArray = Encoding.Default.GetBytes(Text);
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(, ));
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(, ));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, , inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}", b);
}
return ret.ToString();
} #endregion #region ========解密======== /// <summary>
/// 解密
/// </summary>
/// <param name="Text"></param>
/// <returns></returns>
public static string Decrypt(string Text)
{
if (Text == null)
return Text;
return Decrypt(Text, "123456789abcd");
}
/// <summary>
/// 解密数据
/// </summary>
/// <param name="Text"></param>
/// <param name="sKey"></param>
/// <returns></returns>
public static string Decrypt(string Text, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
int len;
len = Text.Length / ;
byte[] inputByteArray = new byte[len];
int x, i;
for (x = ; x < len; x++)
{
i = Convert.ToInt32(Text.Substring(x * , ), );
inputByteArray[x] = (byte)i;
}
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(, ));
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(, ));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, , inputByteArray.Length);
cs.FlushFinalBlock();
return Encoding.Default.GetString(ms.ToArray());
} #endregion

最新文章

  1. [Spring框架]Spring 事务管理基础入门总结.
  2. 《2016ThoughtWorks技术雷达峰会----微服务架构》
  3. hibernate考试题
  4. 工作中一个简单的shell程序
  5. js方法之间的调用之——传参方法
  6. mysql join 查询图
  7. matrix_last_acm_3
  8. 【工具篇】notepad++
  9. The &quot;Run One Program Only&quot; Phenomenon
  10. oracle instr函数
  11. Ubuntu Linux系统下的SVN客户端工具PySVN
  12. 二.java下使用RabbitMQ实现hello world
  13. lesson - 3 笔记 ls /alias /ldd /cd /pwd /环境变量 / 目录
  14. 普通用户添加sudo权限
  15. Leetcode 两数之和 (散列表)
  16. PHP使用MySQL实现消息队列
  17. Scala进阶之路-统计商家id的标签数以及TopN示例案例分析
  18. centos 7.2 安装域名服务器(bind9.9 集群--主从架构),私有域名服务器+缓存
  19. linux内核分析第五周学习笔记
  20. XVFB实现selenium在linux上无界面运行安装篇

热门文章

  1. HDU4080Stammering Aliens(后缀数组+二分)
  2. P2060 [HNOI2006]马步距离
  3. 【Lintcode】033.N-Queens
  4. 洛谷 P3804 [模板] 后缀自动机
  5. 优化EF的性能
  6. JAVA基础知识 String s = new String(&quot;ABC&quot;) VS String s = &quot;abc&quot;
  7. jquery 插件 国外
  8. java.lang.NoClassDefFoundError: org/apache/commons/collections/map/LRUMap 解决方法
  9. Oracle数据去重
  10. bootstrap下拉框式标签页