惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Help Net Security
Help Net Security
G
Google Developers Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Engineering at Meta
Engineering at Meta
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
F
Full Disclosure
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
U
Unit 42
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
C
Cisco Blogs
博客园 - 司徒正美
Project Zero
Project Zero
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
Scott Helme
Scott Helme
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
S
Securelist
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
T
Threatpost
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
The Register - Security
The Register - Security
S
Security Archives - TechRepublic
博客园 - Franky
N
News | PayPal Newsroom
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
W
WeLiveSecurity
A
Arctic Wolf
B
Blog

博客园 - hekeneng

ajax学习例子 SQLServer 存储过程简介与使用方法 二进制数据(Image类型)从一个表存入另一个表 像百度搜索结果一样得到一个关键字左右的若干字符 Javascript操作select控件大全 C#后台调用前台javascript的五种方法 SqlHelper - hekeneng DbHelperSQL 数据访问基础类(基于OleDb)DbHelper js打印局部页面 js刷新页面代码大全 50个网页常用小代码 - hekeneng JS全选反选脚本结合GridView javascript中不可或缺的脚本代码 一些有用的Javscript小技巧 JavaScript 获取runat server控件的控制权(点击Button触发Textbox和Dropdownlist联动为例) JavaScript实用技巧集锦 JavaScript网页特效5则 动态绘制柱状图饼状图
DES加密/解密类。
hekeneng · 2010-03-03 · via 博客园 - hekeneng

using System;
using System.Security.Cryptography; 
using System.Text;
namespace ROYcms.DB
{
 /// <summary>
 /// DES加密/解密类。
 /// </summary>
 public class DESEncrypt
 {
  public DESEncrypt()
  {   
  }

  #region ========加密========
 
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="Text"></param>
        /// <returns></returns>
  public static string Encrypt(string Text)
  {
   return Encrypt(Text,"ROYcms");
  }
  /// <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(0, 8));
   des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
   System.IO.MemoryStream ms=new System.IO.MemoryStream();
   CryptoStream cs=new CryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write);
   cs.Write(inputByteArray,0,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)
  {
            return Decrypt(Text, "ROYcms");
  }
  /// <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/2;
   byte[] inputByteArray = new byte[len];
   int x,i;
   for(x=0;x<len;x++)
   {
    i = Convert.ToInt32(Text.Substring(x * 2, 2), 16);
    inputByteArray[x]=(byte)i;
   }
   des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
   des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
   System.IO.MemoryStream ms=new System.IO.MemoryStream();
   CryptoStream cs=new CryptoStream(ms,des.CreateDecryptor(),CryptoStreamMode.Write);
   cs.Write(inputByteArray,0,inputByteArray.Length);
   cs.FlushFinalBlock();
   return Encoding.Default.GetString(ms.ToArray());
  }
 
  #endregion


 }
}