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.
  1. public static string GetHashValue(byte[] content)
  2. {
  3. string hash;
  4. using (System.Security.Cryptography.SHA1CryptoServiceProvider sha = new System.Security.Cryptography.SHA1CryptoServiceProvider())
  5. {
  6. hash = Convert.ToBase64String(sha.ComputeHash(content));
  7. }
  8. return hash;
  9. }

Happy coding :)

No comments:

Post a Comment