1. /// <summary>
  2. /// DES加密/解密类。
  3. /// </summary>
  4. public class DESEncrypt
  5. {
  6. public DESEncrypt()
  7. {
  8. }
  9.  
  10. #region ========加密========
  11.  
  12. /// <summary>
  13. /// 加密
  14. /// </summary>
  15. /// <param name="Text"></param>
  16. /// <returns></returns>
  17. public static string Encrypt(string Text)
  18. {
  19. return Encrypt(Text,"MATICSOFT");
  20. }
  21. /// <summary>
  22. /// 加密数据
  23. /// </summary>
  24. /// <param name="Text"></param>
  25. /// <param name="sKey"></param>
  26. /// <returns></returns>
  27. public static string Encrypt(string Text,string sKey)
  28. {
  29. DESCryptoServiceProvider des = new DESCryptoServiceProvider();
  30. byte[] inputByteArray;
  31. inputByteArray=Encoding.Default.GetBytes(Text);
  32. des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(, ));
  33. des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(, ));
  34. System.IO.MemoryStream ms=new System.IO.MemoryStream();
  35. CryptoStream cs=new CryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write);
  36. cs.Write(inputByteArray,,inputByteArray.Length);
  37. cs.FlushFinalBlock();
  38. StringBuilder ret=new StringBuilder();
  39. foreach( byte b in ms.ToArray())
  40. {
  41. ret.AppendFormat("{0:X2}",b);
  42. }
  43. return ret.ToString();
  44. }
  45.  
  46. #endregion
  47.  
  48. #region ========解密========
  49.  
  50. /// <summary>
  51. /// 解密
  52. /// </summary>
  53. /// <param name="Text"></param>
  54. /// <returns></returns>
  55. public static string Decrypt(string Text)
  56. {
  57. return Decrypt(Text,"MATICSOFT");
  58. }
  59. /// <summary>
  60. /// 解密数据
  61. /// </summary>
  62. /// <param name="Text"></param>
  63. /// <param name="sKey"></param>
  64. /// <returns></returns>
  65. public static string Decrypt(string Text,string sKey)
  66. {
  67. DESCryptoServiceProvider des = new DESCryptoServiceProvider();
  68. int len;
  69. len=Text.Length/;
  70. byte[] inputByteArray = new byte[len];
  71. int x,i;
  72. for(x=;x<len;x++)
  73. {
  74. i = Convert.ToInt32(Text.Substring(x * , ), );
  75. inputByteArray[x]=(byte)i;
  76. }
  77. des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(, ));
  78. des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(, ));
  79. System.IO.MemoryStream ms=new System.IO.MemoryStream();
  80. CryptoStream cs=new CryptoStream(ms,des.CreateDecryptor(),CryptoStreamMode.Write);
  81. cs.Write(inputByteArray,,inputByteArray.Length);
  82. cs.FlushFinalBlock();
  83. return Encoding.Default.GetString(ms.ToArray());
  84. }
  85.  
  86. #endregion
  87.  
  88. }

DES加密 DESEncrypt的更多相关文章

  1. php和.net的DES加密解密方法

    .net版本 /// <summary> /// DES加密 /// </summary> /// <param name="pToEncrypt"& ...

  2. iOS DES 加密转base64

      //用法 加密转base 64 NSString *str = [self base64StringFromText:@"qingjoin" withKey:@"ke ...

  3. java实现DES加密与解密,md5加密

    很多时候要对秘要进行持久化加密,此时的加密采用md5.采用对称加密的时候就采用DES方法了 import java.io.IOException; import java.security.Messa ...

  4. C# - DES加密+解密

    #region ===========================DES算法=================================== private static string ke ...

  5. des 加密 iOS

    转载请注明原文出处 生成同名的Des.h文件和Des.m文件后,拷贝下方的代码可直接使用.注意在Des.m文件中将key值修改为项目所需的key.--->  #define DesKey 过程很 ...

  6. DES加密和解密PHP,Java,ObjectC统一的方法

    原文:DES加密和解密PHP,Java,ObjectC统一的方法 PHP的加解密函数 <?php class DesComponent { var $key = '12345678'; func ...

  7. 用C#实现DES加密解密解决URL参数明文的问题

    啥也不说,直接上代码. 加密解码,封装到一个类,key可以自己修改. using System; using System.Security.Cryptography; using System.Te ...

  8. C# DES加密类,16位的加密。

    这个加密类是与java写的DES加密不同时,自己写的,最后与Java的加密相同了,解决了加密后不同的问题. 可以直接调用里面的加密和解密的方法. using System; using System. ...

  9. PHP实现DES加密,解决乱码

    PHP要实现DES加密,大体上有2个思路.一是用扩展,一是原生PHP实现. 这里推荐一个PHP原生实现的加密,是thinkphp的一个类库: https://github.com/top-think/ ...

随机推荐

  1. PTA(Basic Level)1024.科学计数法

    科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...

  2. Tomcat解析XML和反射创建对象原理

    Tomcat解析XML和反射创建对象原理 import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Me ...

  3. 经典网络流题目模板(P3376 + P2756 + P3381 : 最大流 + 二分图匹配 + 最小费用最大流)

    题目来源 P3376 [模板]网络最大流 P2756 飞行员配对方案问题 P3381 [模板]最小费用最大流 最大流 最大流问题是网络流的经典类型之一,用处广泛,个人认为网络流问题最具特点的操作就是建 ...

  4. golang 组装返回json数据,提供api接口

    model里 package model type Setting struct { Key string `gorm:"primary_key" json:"key&q ...

  5. [Next] 四.在next中引入redux

    添加 redux 写过 react 稍微复杂一些应用的话,应该都对 redux(mobx)有一定的了解.这次将 redux 引入到项目中 因为之前写项目的习惯,更喜欢使用 redux-thunk 改写 ...

  6. 移动端实1px细线方法

    前言 在移动端中,宽度100%,1px的线看起来要比pc端中宽度100%,1px的线粗, 那是因为css中的1px并不等于移动设备(物理像素)的1px.物理像素显示是1个像素代表2个像素,所以出现为2 ...

  7. luogu题解 P1099 【树网的核】树的直径变式+数据结构维护

    题目链接: https://www.luogu.org/problemnew/show/P1099 https://www.lydsy.com/JudgeOnline/problem.php?id=1 ...

  8. html/css弹性布局的几大常用属性详解

    弹性布局的名称概念: 1.容器:需要添加弹性布局的父元素:项目:弹性布局容器中的每一个子元素,称为项目. 2.主轴:在弹性布局中,我们会通过属性规定水平/垂直方向(flex-direction)为主轴 ...

  9. Ubuntu18.10中pip install mysqlclient 出现EnvironmentError: mysql_config not found错误

    Complete output from command python setup.py egg_info: sh: 1: mysql_config: not found Traceback (mos ...

  10. 17JQuery高级

    1. 动画 1. 三种方式显示和隐藏元素 1. 默认显示和隐藏方式 1. show([speed,[easing],[fn]]) 1. 参数: 1. speed:动画的速度.三个预定义的值(" ...