Skip to content

Instantly share code, notes, and snippets.

@mjs3339
Created August 31, 2018 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjs3339/f3fd3924cfb3dfdb381ca7b45432c2d7 to your computer and use it in GitHub Desktop.
Save mjs3339/f3fd3924cfb3dfdb381ca7b45432c2d7 to your computer and use it in GitHub Desktop.
C# HashAlgorithm Helper Class
public static class HashAlgorithmHelper
{
public static byte[] UpdateHash(this HashAlgorithm hash, byte[] buffer)
{
hash.TransformBlock(buffer, 0, buffer.Length, null, 0);
hash.TransformFinalBlock(new byte[0], 0, 0);
hash.Final();
return hash.Hash;
}
public static void Update(this HashAlgorithm hash, byte[] buffer, int offset, int count)
{
hash.TransformBlock(buffer, offset, count, null, 0);
}
public static void Update(this HashAlgorithm hash, byte[] buffer, int BufferLength)
{
hash.TransformBlock(buffer, 0, BufferLength, null, 0);
}
public static byte[] Final(this HashAlgorithm hash)
{
hash.TransformFinalBlock(new byte[0], 0, 0);
return hash.Hash;
}
public static void Update(this HashAlgorithm hash, byte[] buffer)
{
hash.TransformBlock(buffer, 0, buffer.Length, null, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment