[DEncrypt] DESEncrypt--加密/解密帮助类 (转载)
这个类是关于加密,解密的操作,文件的一些高级操作
1.DESEncrypt加密
2.DESEncrypt解密
看下面代码吧
/// <summary>
/// 类说明:Assistant
/// 编 码 人:苏飞
/// 联系方式:361983679
/// 更新网站:[url=http://www.cckan.net/thread-655-1-1.html]http://www.cckan.net/thread-655-1-1.html[/url]
/// </summary>
using System;
using System.Security.Cryptography;
using System.Text;
namespace DotNet.Utilities
{
/// <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,"MATICSOFT");
}
/// <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)
{
return Decrypt(Text,"MATICSOFT");
}
/// <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 }
}
使用方法也很简单直接调用方法就行了如下
DESEncrypt.Encrypt("要加密的字符串");
DESEncrypt.Decrypt("要解密的字符串");
[DEncrypt] DESEncrypt--加密/解密帮助类 (转载)的更多相关文章
- [DEncrypt] RSACryption--RSA加密/解密字符串 (转载)
点击下载 RSACryption.zip 这个类是关于加密,解密的操作,文件的一些高级操作1.RSACryption RSA 的密钥产生2.RSACryption RSA的加密函数3.RSACrypt ...
- php加密解密功能类
这两天突发奇想想要用php写一个对日常项目加密以及解密的功能,经过努力简单的封装了一个对php代码进行加密解密的类,一些思想也是来自于网络,初步测试用着还行,可以实现对指定项目的加密以及解密(只针对本 ...
- C# MD5加密解密帮助类
/// <summary> /// MD5加密解密帮助类 /// </summary> public static class DESHelper { ...
- php加密解密处理类
[PHP]代码 <?php /*=========================================================== = 版权协议: = GPL (The GN ...
- AES加密解密 助手类 CBC加密模式
"; string result1 = AESHelper.AesEncrypt(str); string result2 = AESHelper.AesDecrypt(result1); ...
- .Net(c#)加密解密工具类:
/// <summary> /// .Net加密解密帮助类 /// </summary> public class NetCryptoHelper { #region des实 ...
- Base64加密解密工具类
使用Apache commons codec类Base64进行加密解密 maven依赖 <dependency> <groupId>commons-codec</grou ...
- [DEncrypt] C# DEncrypt加密/解密帮助类(转载)
点击下载 DEncrypt.rar 这个类是关于加密,解密的操作,文件的一些高级操作1.使用 缺省密钥字符串 加密/解密string2.使用 给定密钥字符串 加密/解密string3.使用 缺省密钥字 ...
- C#工具:加密解密帮助类
using System; using System.IO; using System.Security.Cryptography; using System.Text; //加密字符串,注意strE ...
随机推荐
- java学习多线程之死锁
形成死锁的前提是同步代码块嵌套. 什么是死锁?当一个线程拿到锁以后在这个锁内部的代码需要访问另一段的代码的时候另外一个程序的锁被另外一个线程拿到,这样的话,就造成了两个锁互不想让程序没法往下执行的这种 ...
- MySQL 备份表和数据
方法1: Create table new_table_name (Select * from old_table_name); 方法2: 1.先备份表结构和数据#导出命令 -u用户名 -p密码 -h ...
- 【转】Android 4.2蓝牙介绍
原文网址:http://blog.csdn.net/innost/article/details/9187199 Tieto公司某蓝牙大牛写得<程序员>投稿文章 Android 4.2蓝牙 ...
- 迷宫城堡--HDOJ 1269(Tarjan)
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- .NET混淆工具 (Dotfuscator Professional Edition)
如果不想自己辛辛苦苦码出来的作品被人轻易的破解cpoy就使用这款工具试试吧.^_^ 使用版本:4.9.7500.9484 ,破解版:http://pan.baidu.com/s/1dDH7lr ...
- Selenium终极自动化测试环境搭建(二):Selenium+Eclipse+Python
前面举例了Selenium+Eclipse+Junit+TestNG自动化测试环境的搭建,在前一篇的基础上,下面再举例Selenium+Eclipse+Python测试环境搭建. 第一步:安装Pyth ...
- python 零散记录(二) 序列的相关操作 相加 相乘 改变 复制
序列相加: [1,2] + [3,4] == [1,2,3,4] #字符串也是序列的一种 'hello' + 'world' == 'hello world' #但是序列相加只限于相同类型的序列间相加 ...
- EF多表查询方式
5, 连接 可以的连接有Join 和 GroupJoin 方法.GroupJoin组联接等效于左外部联接,它返回第一个(左侧)数据源的每个元素(即使其他数据源中没有关联元素). using (var ...
- 进军es6(1)---初识es6
es6,全称ECMAScript6(又名es2015).何为ECMAScript?我们常说的Javascript和它又有什么联系呢? 阮一峰老师有一句话描述的比较准确:“ECMAScript是Java ...
- HTML5 Canvas核心技术—图形、动画与游戏开发.pdf5
文本的定位 水平与垂直定位:当使用strokeText()和fillText()绘制文本时,指定了所绘文本的X与Y坐标,还有textAlign与textBaseline两个属性 textAlign:s ...