C# Класс SwfDotNet.IO.Utils.SimpleHash

This class generates and compares hashes using MD5, SHA1, SHA256, SHA384, and SHA512 hashing algorithms.
Before computing a hash, it appends a randomly generated salt to the plain text, and stores this salt appended to the result. To verify another plain text value against the given hash, this class will retrieve the salt value from the hash string and use it when computing a new hash of the plain text. Appending a salt value to the hash may not be the most efficient approach, so when using hashes in a real-life application, you may choose to store them separately. You may also opt to keep results as byte arrays instead of converting them into base64-encoded strings.
Показать файл Открыть проект

Открытые методы

Метод Описание
ComputeHash ( string plainText, string hashAlgorithm, byte saltBytes ) : string

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.

VerifyHash ( string plainText, string hashAlgorithm, string hashValue ) : bool

Compares a hash of the specified plain text value to a given hash value. Plain text is hashed with the same salt value as the original hash.

Описание методов

ComputeHash() публичный статический Метод

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 ComputeHash ( string plainText, string hashAlgorithm, byte saltBytes ) : string
plainText string /// Plaintext value to be hashed. The function does not check whether /// this parameter is null. ///
hashAlgorithm string /// Name of the hash algorithm. Allowed values are: "MD5", "SHA1", /// "SHA256", "SHA384", and "SHA512" (if any other value is specified /// MD5 hashing algorithm will be used). This value is case-insensitive. ///
saltBytes byte /// Salt bytes. This parameter can be null, in which case a random salt /// value will be generated. ///
Результат string

VerifyHash() публичный статический Метод

Compares a hash of the specified plain text value to a given hash value. Plain text is hashed with the same salt value as the original hash.
public static VerifyHash ( string plainText, string hashAlgorithm, string hashValue ) : bool
plainText string /// Plain text to be verified against the specified hash. The function /// does not check whether this parameter is null. ///
hashAlgorithm string /// Name of the hash algorithm. Allowed values are: "MD5", "SHA1", /// "SHA256", "SHA384", and "SHA512" (if any other value is specified, /// MD5 hashing algorithm will be used). This value is case-insensitive. ///
hashValue string /// Base64-encoded hash value produced by ComputeHash function. This value /// includes the original salt appended to it. ///
Результат bool