一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

哈希(不可逆)加密通用类库函数

时间:2008-01-12 编辑:简简单单 来源:一聚教程网

using System;
using System.IO;
using System.Security.Cryptography;
namespace Common
{
///
///Copyright (C), 2004, kwklover(邝伟科)
///File name:Hasher.cs
///Author:邝伟科 Version:1.0 Date:2004年4月22日
///Description:哈希(不可逆)加密通用类库函数
///

public class Hasher
{
private byte[] _HashKey; //哈希密钥存储变量
private string _HashText; //待加密的字符串
public Hasher()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
///
/// 哈希密钥
///

public byte[] HashKey
{
set
{
_HashKey=value;
}
get
{
return _HashKey;
}
}
///
/// 需要产生加密哈希的字符串
///

public string HashText
{
set
{
_HashText=value;
}
get
{
return _HashText;
}
}
///
/// 使用HMACSHA1类产生长度为 20 字节的哈希序列。需提供相应的密钥,接受任何大小的密钥。
///

///
public string HMACSHA1Hasher()
{
byte[] HmacKey=HashKey;
byte[] HmacData=System.Text.Encoding.UTF8.GetBytes(HashText);
HMACSHA1 Hmac = new HMACSHA1(HmacKey);
CryptoStream cs = new CryptoStream(Stream.Null, Hmac, CryptoStreamMode.Write);
cs.Write(HmacData, 0, HmacData.Length);

热门栏目