获得文件的HASH值
代码
public string GetFileHash(string filepath)
{
FileStream filestream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] byt = md5.ComputeHash(filestream);
string hashcode = BitConverter.ToString(byt);
hashcode = hashcode.Replace("-", "");
return hashcode;
}
{
FileStream filestream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] byt = md5.ComputeHash(filestream);
string hashcode = BitConverter.ToString(byt);
hashcode = hashcode.Replace("-", "");
return hashcode;
}
可以唯一标示文件 挺有用。