用C#实现的数据加密(二)——哈希算法
文章作者 100test 发表时间 2007:05:12 12:14:25
来源 100Test.Com百考试题网
计算机等级考试训练软件《百宝箱》
用C#实现的数据加密(二) —— 哈希算法
以下是用C#实现的哈希加密,大家可以根据自己的需要更改所需的算法,文中以SHA1为例:
using System.
using System.IO.
using System.Security.Cryptography.
using System.Text.
namespace DataCrypto
{
///
/// 哈希加密类
/// public class HashMethod
{
private HashAlgorithm HashCryptoService.
///
/// 哈希加密类的构造函数
/// public HashMethod()
{
HashCryptoService = new SHA1Managed().
}
///
/// 加密方法
/// ///
待加密的串
///
经过加密的串public string Encrypto(string Source)
{
byte[] bytIn = UTF8Encoding.UTF8.GetBytes(Source).
byte[] bytOut = HashCryptoService.ComputeHash(bytIn).
return Convert.ToBase64String(bytOut).
}
}
}