HashFunction Component
Properties Methods Events Configuration Settings Errors
The HashFunction component implements a wide variety of algorithms for message hashing.
Syntax
SecureBlackboxLite.Hashfunction
Remarks
HashFunction allows you to hash messages using a variety of industry standard hashing algorithms. Algorithms of both Hash and HMAC type are supported.
You can feed your data to HashFunction in one go, or in chunks. Use Hash method to initialize the hash function, pass the buffer, and calculate the hash in one line of code.
Alternatively, use Reset, Update, and Finish in sequence to perform each of those steps individually. You can call Update (and its UpdateFile and
UpdateStream variants) repeatedly between Reset and Finish, effectively passing the data in a number of portions:
// Feeding the data in one go: Hashfunction hf = new Hashfunction(); hf.Algorithm = "SHA256"; byte[] hash = hf.Hash(buffer); // Feeding data chunk by chunk: Hashfunction hf = new Hashfunction(); hf.Algorithm = "SHA256"; hf.Reset(); hf.Update(buffer1); hf.Update(buffer2); hf.Update(buffer3); byte[] hash = hf.Finish();
To use keyed HMAC, you need to provide the secret key first. Use CryptoKeyManager to create and initialize the key object:
Cryptokeymanager km = new Cryptokeymanager(); km.ImportBytes(hmacKey, Constants.kffDER, "SHA256", "", "", Constants.ktSecret); Hashfunction hf = new Hashfunction(); hf.Algorithm = "SHA256"; hf.Key = km.Key; byte[] hash = hf.Hash(buffer);
Use OutputEncoding to set the desired encoding method.
Property List
The following is the full list of the properties of the component with short descriptions. Click on the links for further details.
Algorithm | The hash algorithm to use when hashing data. |
InputStream | A stream containing the input data. |
JsonSettings | Provides a container for JSON settings. |
Key | The key to use during the hashing. |
OutputEncoding | The encoding to use for the output data. |
Method List
The following is the full list of the methods of the component with short descriptions. Click on the links for further details.
config | Sets or retrieves a configuration setting. |
finish | Completes the hash and returns the resulting message digest. |
hash | Calculates a message digest over a byte array. |
hashFile | Calculates a message digest over data contained in a file. |
hashStream | Calculates a message digest over data contained in a stream. |
reset | Resets the hash function context. |
update | Feeds a chunk of data to the hash function. |
updateFile | Feeds the contents of a file to the hash function. |
updateStream | Feeds the contents of a stream to the hash function. |
Event List
The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.
Error | Informs about errors during cryptographic operations. |
Notification | This event notifies the application about an underlying control flow event. |
Configuration Settings
The following is a list of configuration settings for the component with short descriptions. Click on the links for further details.
TempPath | Path for storing temporary files. |