Generates a hash for the given plain text value and returns a base64-encoded result. Before the hash is computed, a random salt is generated and appended to the plain text. This salt is stored at the end of the hash value, so it can be used later for hash verification.

public static string ComputeHash(string plainText,
	string hashAlgorithm,
	string salt,
	bool useBinHex)

Return Value

Hash value formatted as a base64-encoded or BinHex stringstring.


Plaintext value to be hashed.

Name of the hash algorithm. Allowed values are: "MD5", "SHA1", "SHA256", "SHA384", "SHA512", "HMACMD5", "HMACSHA1", "HMACSHA256", "HMACSHA512" (if any other value is specified MD5 will be used).

        HMAC algorithms uses Hash-based Message Authentication Code.
        The HMAC process mixes a secret key with the message data, hashes 
        the result with the hash function, mixes that hash value with 
        the secret key again, and then applies the hash function
        a second time. HMAC hashes are fixed lenght and generally
        much longer than non-HMAC hashes of the same type.
        This value is case-insensitive.

Optional but recommended salt string to apply to the hash. If not passed the raw encoding is used. If salt is nullthe raw algorithm is used (useful for file hashes etc.) HMAC versions REQUIRE that salt is passed.

if true returns the data as BinHex byte pair string. Otherwise Base64 is returned.


See also:

Class Encryption

© West Wind Technologies, 2019 • Updated: 06/23/19
Comment or report problem with topic