Class HashHelper
- Namespace
- SunamoShared.Crypting
- Assembly
- SunamoShared.dll
Provides methods for computing SHA256 and MD5 hashes, with optional salt generation and verification.
public class HashHelper
- Inheritance
-
HashHelper
- Inherited Members
- Extension Methods
Methods
GetHash(byte[])
Computes a SHA256 hash of the input byte array (salt must already be included if needed).
public static byte[] GetHash(byte[] input)
Parameters
inputbyte[]The byte array to hash.
Returns
- byte[]
GetHash(byte[], byte[])
Computes a SHA256 hash of the password bytes combined with salt bytes.
public static byte[] GetHash(byte[] passwordBytes, byte[] saltBytes)
Parameters
Returns
- byte[]
GetHashAndSalt(byte[], out byte[], out byte[])
Generates a random 10-byte salt, combines it with the password bytes, and computes a SHA256 hash.
public static void GetHashAndSalt(byte[] passwordBytes, out byte[] hash, out byte[] saltBytes)
Parameters
passwordBytesbyte[]The password byte array.
hashbyte[]The computed hash output.
saltBytesbyte[]The generated salt output.
GetHashAndSalt(byte[], out byte[], out byte[], int)
Generates a random salt of specified length, combines it with the password bytes, and computes a SHA256 hash.
public static void GetHashAndSalt(byte[] passwordBytes, out byte[] hash, out byte[] saltBytes, int saltByteCount)
Parameters
passwordBytesbyte[]The password byte array.
hashbyte[]The computed hash output.
saltBytesbyte[]The generated salt output.
saltByteCountintThe number of random bytes for the salt.
GetHashString(string)
Computes a SHA256 hash of the input string and returns it as a UTF8 string.
public static string GetHashString(string text)
Parameters
textstringThe input string to hash.
Returns
GetMd5Hash(string)
Computes an MD5 hash of the input text using UTF8 encoding.
public static string GetMd5Hash(string text)
Parameters
textstringThe input text to hash.
Returns
GetMd5Hash(string, Encoding)
Computes an MD5 hash of the input text using the specified encoding.
public static string GetMd5Hash(string text, Encoding encoding)
Parameters
textstringThe input text to hash.
encodingEncodingThe encoding to use for converting the text to bytes.
Returns
PairHashAndPassword(byte[], byte[], byte[])
Verifies that the password matches the stored hash by combining it with the salt and comparing.
public static bool PairHashAndPassword(byte[] hash, byte[] saltBytes, byte[] passwordBytes)
Parameters
hashbyte[]The stored hash to compare against.
saltBytesbyte[]The salt used in the original hash.
passwordBytesbyte[]The password bytes to verify.