Created
August 31, 2018 17:19
-
-
Save mjs3339/f3fd3924cfb3dfdb381ca7b45432c2d7 to your computer and use it in GitHub Desktop.
C# HashAlgorithm Helper Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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