.GetBytes(str);
byte hashed=md5.ComputeHash(toCompute,0,toCompute.Length);
return Encoding.ASCII.GetString(hashed);
}
/**//// <summary>
/// 根据文件来计算散列值
/// </summary>
/// <param name="filePath">要计算散列值的文件路径</param>
/// <returns></returns>
public string GetMD5FromFile(string filePath)
{
bool isExist=File.Exists(filePath);
if(isExist)//如果文件存在
{
FileStream stream=new FileStream(filePath,FileMode.Open,FileAccess.Read);
StreamReader reader=new StreamReader(stream,Encoding.Unicode);
string str=reader.ReadToEnd();
byte toHash=Encoding.Unicode.GetBytes(str);
byte hashed=md5.ComputeHash(toHash,0,toHash.Length);
stream.Close();
return Encoding.ASCII.GetString(hashed);
}
else//文件不存在
{
throw new FileNotFoundException("指定的文件没有找到");
}
}
}
/**//// <summary>
/// 用于数字签名的hash类
/// </summary>
public class MACTripleDESEncrypt
{
private MACTripleDES mact;
private string __key="ksn168ch";
private byte __data=null;
public MACTripleDESEncrypt()
{
mact=new MACTripleDES();
}
/**//// <summary>
/// 获取或设置用于数字签名的密钥
/// </summary>
public string Key
{
get{return this.__key;}
set
{
int keyLength=value.Length;
int keyAllowLengths=new int{8,16,24};
bool isRight=false;
foreach(int i in keyAllowLengths)
{
if(keyLength==keyAllowLengths[i])
{
isRight=true;
break;
}
}
if(!isRight)
throw new ApplicationException("用于数字签名的密钥长度必须是8,16,24值之一");
else
this.__key=value;
}
}
/**//// <summary>
/// 获取或设置用于数字签名的用户数据
/// </summary>
public byte Data
{
get{return this.__data;}
set{this.__data=value;}
}
/**//// <summary>
/// 得到签名后的hash值
/// </summary>
/// <returns></returns>
public string GetHashValue()
{
if(this.Data==null)
throw new NotSetSpecialPropertyException("没有设置要进行数字签名的用户"+