这个类是关于加密,解密的操作,文件的一些高级操作
1.Encrypt加密
2.Encrypt解密
3.Encrypt MD5加密
看下面代码吧
/// <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.IO; namespace DotNet.Utilities
{
/// <summary>
/// 加密解密实用类。
/// </summary>
public class Encrypt
{
//密钥
private static byte[] arrDESKey = new byte[] {, , , , , , , };
private static byte[] arrDESIV = new byte[] {, , , , , , , }; /// <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(), , (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);
}
}
}