Encrypt--加密/解密/MD5加密
导读部分
-------------------------------------------------------------------------------------------------------------
C#基类库苏飞版--系列教程导航 http://www.sufeinet.com/thread-655-1-1.html
下载之前你首先要注册成为会员哦,注册之后就可以直接下载啦
更新时间:2012-12-06
最新的Encrypt类下载:
Encrypt.zip
(1.07 KB, 下载次数: 303)
这个类是关于加密,解密的操作,文件的一些高级操作
1.Encrypt加密
2.Encrypt解密
3.Encrypt MD5加密
看下面代码吧
[C#] 纯文本查看 复制代码 /// <summary>
/// 类说明:Assistant
/// 编 码 人:苏飞
/// 联系方式:361983679
/// 更新网站:[url=http://www.sufeinet.com/thread-655-1-1.html]http://www.sufeinet.com/thread-655-1-1.html[/url]
/// </summary>
using System;
using System.Security.Cryptography;
using System.IO;
namespace DotNet.Utilities
{
/// <summary>
/// 加密解密实用类。
/// </summary>
public class Encrypt
{
//密钥
private static byte[] arrDESKey = new byte[] {42, 16, 93, 156, 78, 4, 218, 32};
private static byte[] arrDESIV = new byte[] {55, 103, 246, 79, 36, 99, 167, 3};
/// <summary>
/// 加密。
/// </summary>
/// <param name="m_Need_Encode_String"></param>
/// <returns></returns>
public static string Encode(string m_Need_Encode_String)
{
if (m_Need_Encode_String == null)
{
throw new Exception("Error: \n源字符串为空!!");
}
DESCryptoServiceProvider objDES = new DESCryptoServiceProvider();
MemoryStream objMemoryStream = new MemoryStream();
CryptoStream objCryptoStream = new CryptoStream(objMemoryStream,objDES.CreateEncryptor(arrDESKey,arrDESIV),CryptoStreamMode.Write);
StreamWriter objStreamWriter = new StreamWriter(objCryptoStream);
objStreamWriter.Write(m_Need_Encode_String);
objStreamWriter.Flush();
objCryptoStream.FlushFinalBlock();
objMemoryStream.Flush();
return Convert.ToBase64String(objMemoryStream.GetBuffer(), 0, (int)objMemoryStream.Length);
}
/// <summary>
/// 解密。
/// </summary>
/// <param name="m_Need_Encode_String"></param>
/// <returns></returns>
public static string Decode(string m_Need_Encode_String)
{
if (m_Need_Encode_String == null)
{
throw new Exception("Error: \n源字符串为空!!");
}
DESCryptoServiceProvider objDES = new DESCryptoServiceProvider();
byte[] arrInput = Convert.FromBase64String(m_Need_Encode_String);
MemoryStream objMemoryStream = new MemoryStream(arrInput);
CryptoStream objCryptoStream = new CryptoStream(objMemoryStream,objDES.CreateDecryptor(arrDESKey,arrDESIV),CryptoStreamMode.Read);
StreamReader objStreamReader = new StreamReader(objCryptoStream);
return objStreamReader.ReadToEnd();
}
/// <summary>
/// md5
/// </summary>
/// <param name="encypStr"></param>
/// <returns></returns>
public static string Md5(string encypStr)
{
string retStr;
MD5CryptoServiceProvider m5 = new MD5CryptoServiceProvider();
byte[] inputBye;
byte[] outputBye;
inputBye = System.Text.Encoding.ASCII.GetBytes(encypStr);
outputBye = m5.ComputeHash(inputBye);
retStr = Convert.ToBase64String(outputBye);
return (retStr);
}
}
}
|