获得文件的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;
    }

 

可以唯一标示文件 挺有用。

posted @ 2010-06-03 16:27  melody&bobo  阅读(304)  评论(0编辑  收藏  举报