HashCryptographer

A hash provider for any hash algorithm which derives from HashAlgorithm.

Namespace:
KpokPatagon.Security.Cryptography
Type:
Class
Public:
Yes
Protected:
No
Sealed:
No
Abstract:
No
Implements:
KpokPatagon.Security.Cryptography.IHashProvider, System.IDisposable

Constructors

HashCryptographer

Creates a new instance of HashCryptographer and initialize it as a salt disabled algorithm.

Signature:
public Void HashCryptographer(algorithm)
Parameters
Name Type Summary
algorithm HashAlgorithm The HashAlgorithm to use.

HashCryptographer

Creates a new instance of HashCryptographer and initializes it.

Signature:
public Void HashCryptographer(algorithm, saltEnabled)
Parameters
Name Type Summary
algorithm HashAlgorithm The HashAlgorithm to use.
saltEnabled Boolean true if salt sould be applied; otherwise false.
Exceptions
Type Summary
ArgumentNullException Thrown when algorithm is null.

Methods

CompareHash

Compares a plain text input with a computed hash.

Signature:
public Boolean CompareHash(plaintext, hashedtext)
Returns

true if plaintext hashed is equal to hashedtext, false otherwise.

Parameters
Name Type Summary
plaintext Byte[] The input to compare with the hash.
hashedtext Byte[] The hash value to compare with the input value.
Exceptions
Type Summary
ArgumentNullException Thrown when plaintext or hashedtext are null.
ArgumentException Thrown then hashedtext is zero bytes length.

ComputeHash

Compute the hash value of plain text.

Signature:
public Byte[] ComputeHash(plaintext)
Returns

The computed hash code.

Parameters
Name Type Summary
plaintext Byte[] The input to compute the hash for.

ComputeHash

Computes the hash value for stream. If stream is empty null is returned.

Signature:
public Byte[] ComputeHash(stream)
Returns

The computed hash code.

Remarks

Even if configured, Salt is not used by this method.

Parameters
Name Type Summary
stream Stream The input Stream for wich to compute the hash.
Exceptions
Type Summary
ArgumentNullException Thrown when stream is null.

ComputeHashWithSalt

Computes a hash with the specified salt.

Signature:
protected Byte[] ComputeHashWithSalt(plaintext, salt)
Returns

The computed hash.

Parameters
Name Type Summary
plaintext Byte[] The plain text to hash.
salt Byte[] The hash salt.

Dispose

Clean up.

Signature:
public Void Dispose()

ExtractSalt

Extracts the salt value from the hashed text.

Signature:
protected Byte[] ExtractSalt(hashedtext)
Returns

The extracted salt.

Parameters
Name Type Summary
hashedtext Byte[] The hash from which to extract the salt.
Exceptions
Type Summary
ArgumentNullException Thrown when hashedtext is null.