Statistics
| Branch: | Revision:

root / trunk / Pithos.Core / Signature.cs @ 82db721b

History | View | Annotate | Download (645 Bytes)

1
using System.IO;
2
using System.Security.Cryptography;
3
using System.Text;
4

    
5
public static class Signature
6
{
7
    public static string CalculateHash(string path)
8
    {
9
        string hash;
10
        using (var hasher = MD5.Create())
11
        using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, true))
12
        {
13
            var hashBytes = hasher.ComputeHash(stream);
14
            var hashBuilder = new StringBuilder();
15
            foreach (byte b in hashBytes)
16
                hashBuilder.Append(b.ToString("x2").ToLower());
17
            hash = hashBuilder.ToString();
18
        }
19
        return hash;
20
    }
21
}