Wednesday, September 17, 2014

Get the Hash value of a file byte[] (byte array) in CSharp ( C# )

Here is a simple code to get the Hash value of a byte[] (byte array). The byte[] can be from any file. You can see my previous post to get the hash value directly from file. Click Here.
public static string GetHashValue(byte[] content)
{
    string hash;
    using (System.Security.Cryptography.SHA1CryptoServiceProvider sha = new System.Security.Cryptography.SHA1CryptoServiceProvider())
    {
        hash = Convert.ToBase64String(sha.ComputeHash(content));
    }
    return hash;
}

Happy coding :)

No comments:

Post a Comment