HashFunction Class
Properties Methods Events Configuration Settings Errors
The HashFunction class implements a wide variety of algorithms for message hashing.
Class Name
SecureBlackboxLite_HashFunction
Procedural Interface
secureblackboxlite_hashfunction_open(); secureblackboxlite_hashfunction_close($res); secureblackboxlite_hashfunction_register_callback($res, $id, $function); secureblackboxlite_hashfunction_get_last_error($res); secureblackboxlite_hashfunction_get_last_error_code($res); secureblackboxlite_hashfunction_set($res, $id, $index, $value); secureblackboxlite_hashfunction_get($res, $id, $index); secureblackboxlite_hashfunction_do_config($res, $configurationstring); secureblackboxlite_hashfunction_do_finish($res); secureblackboxlite_hashfunction_do_hash($res, $buffer); secureblackboxlite_hashfunction_do_hashfile($res, $sourcefile); secureblackboxlite_hashfunction_do_hashstream($res); secureblackboxlite_hashfunction_do_reset($res); secureblackboxlite_hashfunction_do_update($res, $buffer); secureblackboxlite_hashfunction_do_updatefile($res, $sourcefile); secureblackboxlite_hashfunction_do_updatestream($res);
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 class with short descriptions. Click on the links for further details.
Algorithm | The hash algorithm to use when hashing data. |
JsonKeyHeaderParams | Contains key header parameters. |
JsonProtectedHeader | Provides access to the header being protected. |
JsonUnprotectedHeader | Provides access to the unprotected part of the header. |
JsonUnprotectedHeaderParams | Contains unprotected header parameters. |
KeyAlgorithm | The algorithm of the cryptographic key. |
KeyBits | The length of the key in bits. |
KeyExportable | Returns True if the key is exportable (can be serialized into an array of bytes), and False otherwise. |
KeyHandle | Allows to get or set a 'handle', a unique identifier of the underlying property object. |
KeyID | Provides access to a storage-specific key identifier. |
KeyIV | The initialization vector (IV) of a symmetric key. |
KeyKey | The byte array representation of the key. |
KeyNonce | A nonce value associated with a key. |
KeyPrivate | Returns True if the object hosts a private key, and False otherwise. |
KeyPublic | Returns True if the object hosts a public key, and False otherwise. |
KeySubject | Returns the key subject. |
KeySymmetric | Returns True if the object contains a symmetric key, and False otherwise. |
KeyValid | Returns True if this key is valid. |
OutputEncoding | The encoding to use for the output data. |
Method List
The following is the full list of the methods of the class 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 class 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 class with short descriptions. Click on the links for further details.
TempPath | Path for storing temporary files. |