HashFunction Component
Properties Methods Events Config Settings Errors
The HashFunction component implements a wide variety of algorithms for message hashing.
Syntax
TsbxHashFunction
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. |
FIPSMode | Reserved. |
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. |
KeyHandle | Allows to get or set a 'handle', a unique identifier of the underlying property object. |
KeyKey | The byte array representation of the key. |
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. |
DoAction | Performs an additional action. |
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. |
Config Settings
The following is a list of config settings for the component with short descriptions. Click on the links for further details.
TempPath | Path for storing temporary files. |
ASN1UseGlobalTagCache | Controls whether ASN.1 module should use a global object cache. |
AssignSystemSmartCardPins | Specifies whether CSP-level PINs should be assigned to CNG keys. |
CheckKeyIntegrityBeforeUse | Enables or disable private key integrity check before use. |
CookieCaching | Specifies whether a cookie cache should be used for HTTP(S) transports. |
Cookies | Gets or sets local cookies for the component. |
DefDeriveKeyIterations | Specifies the default key derivation algorithm iteration count. |
DNSLocalSuffix | The suffix to assign for TLD names. |
EnableClientSideSSLFFDHE | Enables or disables finite field DHE key exchange support in TLS clients. |
GlobalCookies | Gets or sets global cookies for all the HTTP transports. |
HardwareCryptoUsePolicy | The hardware crypto usage policy. |
HttpUserAgent | Specifies the user agent name to be used by all HTTP clients. |
HttpVersion | The HTTP version to use in any inner HTTP client components created. |
IgnoreExpiredMSCTLSigningCert | Whether to tolerate the expired Windows Update signing certificate. |
ListDelimiter | The delimiter character for multi-element lists. |
LogDestination | Specifies the debug log destination. |
LogDetails | Specifies the debug log details to dump. |
LogFile | Specifies the debug log filename. |
LogFilters | Specifies the debug log filters. |
LogFlushMode | Specifies the log flush mode. |
LogLevel | Specifies the debug log level. |
LogMaxEventCount | Specifies the maximum number of events to cache before further action is taken. |
LogRotationMode | Specifies the log rotation mode. |
MaxASN1BufferLength | Specifies the maximal allowed length for ASN.1 primitive tag data. |
MaxASN1TreeDepth | Specifies the maximal depth for processed ASN.1 trees. |
OCSPHashAlgorithm | Specifies the hash algorithm to be used to identify certificates in OCSP requests. |
OldClientSideRSAFallback | Specifies whether the SSH client should use a SHA1 fallback. |
PKICache | Specifies which PKI elements (certificates, CRLs, OCSP responses) should be cached. |
PKICachePath | Specifies the file system path where cached PKI data is stored. |
ProductVersion | Returns the version of the SecureBlackbox library. |
ServerSSLDHKeyLength | Sets the size of the TLS DHE key exchange group. |
StaticDNS | Specifies whether static DNS rules should be used. |
StaticIPAddress[domain] | Gets or sets an IP address for the specified domain name. |
StaticIPAddresses | Gets or sets all the static DNS rules. |
Tag | Allows to store any custom data. |
TLSSessionGroup | Specifies the group name of TLS sessions to be used for session resumption. |
TLSSessionLifetime | Specifies lifetime in seconds of the cached TLS session. |
TLSSessionPurgeInterval | Specifies how often the session cache should remove the expired TLS sessions. |
UseCRLObjectCaching | Specifies whether reuse of loaded CRL objects is enabled. |
UseInternalRandom | Switches between SecureBlackbox-own and platform PRNGs. |
UseLegacyAdESValidation | Enables legacy AdES validation mode. |
UseOCSPResponseObjectCaching | Specifies whether reuse of loaded OCSP response objects is enabled. |
UseOwnDNSResolver | Specifies whether the client components should use own DNS resolver. |
UseSharedSystemStorages | Specifies whether the validation engine should use a global per-process copy of the system certificate stores. |
UseSystemNativeSizeCalculation | An internal CryptoAPI access tweak. |
UseSystemOAEPAndPSS | Enforces or disables the use of system-driven RSA OAEP and PSS computations. |
UseSystemRandom | Enables or disables the use of the OS PRNG. |
XMLRDNDescriptorName[OID] | Defines an OID mapping to descriptor names for the certificate's IssuerRDN or SubjectRDN. |
XMLRDNDescriptorPriority[OID] | Specifies the priority of descriptor names associated with a specific OID. |
XMLRDNDescriptorReverseOrder | Specifies whether to reverse the order of descriptors in RDN. |
XMLRDNDescriptorSeparator | Specifies the separator used between descriptors in RDN. |
Algorithm Property (HashFunction Component)
The hash algorithm to use when hashing data.
Syntax
__property String Algorithm = { read=FAlgorithm, write=FSetAlgorithm };
Default Value
"SHA256"
Remarks
SB_HASH_ALGORITHM_SHA1 | SHA1 | |
SB_HASH_ALGORITHM_SHA224 | SHA224 | |
SB_HASH_ALGORITHM_SHA256 | SHA256 | |
SB_HASH_ALGORITHM_SHA384 | SHA384 | |
SB_HASH_ALGORITHM_SHA512 | SHA512 | |
SB_HASH_ALGORITHM_MD2 | MD2 | |
SB_HASH_ALGORITHM_MD4 | MD4 | |
SB_HASH_ALGORITHM_MD5 | MD5 | |
SB_HASH_ALGORITHM_RIPEMD160 | RIPEMD160 | |
SB_HASH_ALGORITHM_CRC32 | CRC32 | |
SB_HASH_ALGORITHM_SSL3 | SSL3 | |
SB_HASH_ALGORITHM_GOST_R3411_1994 | GOST1994 | |
SB_HASH_ALGORITHM_WHIRLPOOL | WHIRLPOOL | |
SB_HASH_ALGORITHM_POLY1305 | POLY1305 | |
SB_HASH_ALGORITHM_SHA3_224 | SHA3_224 | |
SB_HASH_ALGORITHM_SHA3_256 | SHA3_256 | |
SB_HASH_ALGORITHM_SHA3_384 | SHA3_384 | |
SB_HASH_ALGORITHM_SHA3_512 | SHA3_512 | |
SB_HASH_ALGORITHM_BLAKE2S_128 | BLAKE2S_128 | |
SB_HASH_ALGORITHM_BLAKE2S_160 | BLAKE2S_160 | |
SB_HASH_ALGORITHM_BLAKE2S_224 | BLAKE2S_224 | |
SB_HASH_ALGORITHM_BLAKE2S_256 | BLAKE2S_256 | |
SB_HASH_ALGORITHM_BLAKE2B_160 | BLAKE2B_160 | |
SB_HASH_ALGORITHM_BLAKE2B_256 | BLAKE2B_256 | |
SB_HASH_ALGORITHM_BLAKE2B_384 | BLAKE2B_384 | |
SB_HASH_ALGORITHM_BLAKE2B_512 | BLAKE2B_512 | |
SB_HASH_ALGORITHM_SHAKE_128 | SHAKE_128 | |
SB_HASH_ALGORITHM_SHAKE_256 | SHAKE_256 | |
SB_HASH_ALGORITHM_SHAKE_128_LEN | SHAKE_128_LEN | |
SB_HASH_ALGORITHM_SHAKE_256_LEN | SHAKE_256_LEN |
Data Type
String
FIPSMode Property (HashFunction Component)
Reserved.
Syntax
__property bool FIPSMode = { read=FFIPSMode, write=FSetFIPSMode };
Default Value
false
Remarks
This property is reserved for future use.
Data Type
Boolean
JsonKeyHeaderParams Property (HashFunction Component)
Contains key header parameters.
Syntax
__property String JsonKeyHeaderParams = { read=FJsonKeyHeaderParams, write=FSetJsonKeyHeaderParams };
Default Value
"kid"
Remarks
Contains key header parameters.
Data Type
String
JsonProtectedHeader Property (HashFunction Component)
Provides access to the header being protected.
Syntax
__property String JsonProtectedHeader = { read=FJsonProtectedHeader, write=FSetJsonProtectedHeader };
Default Value
""
Remarks
Provides access to the header being protected.
Data Type
String
JsonUnprotectedHeader Property (HashFunction Component)
Provides access to the unprotected part of the header.
Syntax
__property String JsonUnprotectedHeader = { read=FJsonUnprotectedHeader, write=FSetJsonUnprotectedHeader };
Default Value
""
Remarks
Provides access to the unprotected part of the header.
Data Type
String
JsonUnprotectedHeaderParams Property (HashFunction Component)
Contains unprotected header parameters.
Syntax
__property String JsonUnprotectedHeaderParams = { read=FJsonUnprotectedHeaderParams, write=FSetJsonUnprotectedHeaderParams };
Default Value
""
Remarks
Contains unprotected header parameters.
Data Type
String
KeyHandle Property (HashFunction Component)
Allows to get or set a 'handle', a unique identifier of the underlying property object.
Syntax
__property __int64 KeyHandle = { read=FKeyHandle, write=FSetKeyHandle };
Default Value
0
Remarks
Allows to get or set a 'handle', a unique identifier of the underlying property object. Use this property to assign objects of the same type in a quicker manner, without copying them fieldwise.
When you pass a handle of one object to another, the source object is copied to the destination rather than assigned. It is safe to get rid of the original object
after such operation.
pdfSigner.setSigningCertHandle(certMgr.getCertHandle());
This property is not available at design time.
Data Type
Long64
KeyKey Property (HashFunction Component)
The byte array representation of the key.
Syntax
__property DynamicArrayKeyKey = { read=FKeyKey };
Remarks
The byte array representation of the key. This may not be available for non-KeyExportable keys.
This property is read-only and not available at design time.
Data Type
Byte Array
OutputEncoding Property (HashFunction Component)
The encoding to use for the output data.
Syntax
__property TsbxHashFunctionOutputEncodings OutputEncoding = { read=FOutputEncoding, write=FSetOutputEncoding };
enum TsbxHashFunctionOutputEncodings { cetDefault=0, cetBinary=1, cetBase64=2, cetCompact=3, cetJSON=4 };
Default Value
cetDefault
Remarks
Use this property to configure the type of encoding to be used for the output data.
cetDefault | 0 | The default encoding type in current circumstances. This depends on the operation and the type of the key being used. |
cetBinary | 1 | Raw binary encoding (no encoding) |
cetBase64 | 2 | Base64 encoding (armouring) |
cetCompact | 3 | JSON compact encoding |
cetJSON | 4 | JSON standard encoding |
Data Type
Integer
Config Method (HashFunction Component)
Sets or retrieves a configuration setting.
Syntax
String __fastcall Config(String ConfigurationString);
Remarks
Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.
These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.
To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).
To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.
DoAction Method (HashFunction Component)
Performs an additional action.
Syntax
String __fastcall DoAction(String ActionID, String ActionParams);
Remarks
DoAction is a generic method available in every component. It is used to perform an additional action introduced after the product major release. The list of actions is not fixed, and may be flexibly extended over time.
The unique identifier (case insensitive) of the action is provided in the ActionID parameter.
ActionParams contains the value of a single parameter, or a list of multiple parameters for the action in the form of PARAM1=VALUE1;PARAM2=VALUE2;....
Common ActionIDs:
Action | Parameters | Returned value | Description |
ResetTrustedListCache | none | none | Clears the cached list of trusted lists. |
ResetCertificateCache | none | none | Clears the cached certificates. |
ResetCRLCache | none | none | Clears the cached CRLs. |
ResetOCSPResponseCache | none | none | Clears the cached OCSP responses. |
Finish Method (HashFunction Component)
Completes the hash and returns the resulting message digest.
Syntax
DynamicArray<Byte> __fastcall Finish();
Remarks
This method finalizes the hashing operation and returns the message digest of the input data. Use it in conjuction with Reset and Update methods to process data in chunks.
Hash Method (HashFunction Component)
Calculates a message digest over a byte array.
Syntax
DynamicArray<Byte> __fastcall Hash(DynamicArray<Byte> Buffer);
Remarks
This method calculates and returns a message digest over the content of Buffer. This is a quick way to calculate a hash over a byte array in one go.
HashFile Method (HashFunction Component)
Calculates a message digest over data contained in a file.
Syntax
DynamicArray<Byte> __fastcall HashFile(String SourceFile);
Remarks
This method calculates and returns a message digest over the data contained in file SourceFile. This is a quick way to calculate a hash over a file content in one go.
HashStream Method (HashFunction Component)
Calculates a message digest over data contained in a stream.
Syntax
DynamicArray<Byte> __fastcall HashStream();
Remarks
This method calculates a message digest over the data contained in InputStream. This is a quick way of calculating a message data over a stream content in one go.
Reset Method (HashFunction Component)
Resets the hash function context.
Syntax
void __fastcall Reset();
Remarks
Reset resets the context of the hash function, discarding any data passed to it previously.
Use this method to restart the hash calculation process from scratch.
This method does not affect one-go methods like Hash or HashStream; they reset the hash function context automatically.
Update Method (HashFunction Component)
Feeds a chunk of data to the hash function.
Syntax
void __fastcall Update(DynamicArray<Byte> Buffer);
Remarks
This method feeds Buffer to the hash function. Call this method repeatedly to pass your data to the hash function chunk by chunk.
Remember to initialize the hash function with an Reset call before starting to feed data with this method. After the whole volume of data has been sent, complete the calculation and obtain the resulting message digest with a Finish call.
UpdateFile Method (HashFunction Component)
Feeds the contents of a file to the hash function.
Syntax
void __fastcall UpdateFile(String SourceFile);
Remarks
Call this method to pass the contents of a file to the hash function. You can call this function repeatedly and mix it with Update to feed the hash function with many separate chunks of data.
Remember to initialize the hash function with an Reset call before starting hashing the data. Once all the data chunks have been submitted, finalize the hash function and obtain the resulting message digest by calling Finish.
UpdateStream Method (HashFunction Component)
Feeds the contents of a stream to the hash function.
Syntax
void __fastcall UpdateStream();
Remarks
Call this method to pass the contents of a stream to the hash function. You can call this function repeatedly and mix it with Update to feed the hash function with many separate chunks of data.
Remember to initialize the hash function with an Reset call before starting hashing the data. Once all the data chunks have been submitted, finalize the hash function and obtain the resulting message digest by calling Finish.
Error Event (HashFunction Component)
Informs about errors during cryptographic operations.
Syntax
typedef struct { int ErrorCode; String Description; } TsbxHashFunctionErrorEventParams; typedef void __fastcall (__closure *TsbxHashFunctionErrorEvent)(System::TObject* Sender, TsbxHashFunctionErrorEventParams *e); __property TsbxHashFunctionErrorEvent OnError = { read=FOnError, write=FOnError };
Remarks
Component fires this event if an error happens during a cryptographic operation.
ErrorCode contains an error code and Description contains a textual description of the error that happened.
Notification Event (HashFunction Component)
This event notifies the application about an underlying control flow event.
Syntax
typedef struct { String EventID; String EventParam; } TsbxHashFunctionNotificationEventParams; typedef void __fastcall (__closure *TsbxHashFunctionNotificationEvent)(System::TObject* Sender, TsbxHashFunctionNotificationEventParams *e); __property TsbxHashFunctionNotificationEvent OnNotification = { read=FOnNotification, write=FOnNotification };
Remarks
The component fires this event to let the application know about some event, occurrence, or milestone in the component. For example, it may fire to report completion of the document processing. The list of events being reported is not fixed, and may be flexibly extended over time.
The unique identifier of the event is provided in the EventID parameter. EventParam contains any parameters accompanying the occurrence. Depending on the type of the component, the exact action it is performing, or the document being processed, one or both may be omitted.
Config Settings (HashFunction Component)
The component accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.HashFunction Config Settings
Base Config Settings
You can switch this property off to improve performance if your project only uses known, good private keys.
Supported values are:
off | No caching (default) | |
local | Local caching | |
global | Global caching |
This setting only applies to sessions negotiated with TLS version 1.3.
Supported values are:
file | File | |
console | Console | |
systemlog | System Log (supported for Android only) | |
debugger | Debugger (supported for VCL for Windows and .Net) |
Supported values are:
time | Current time | |
level | Level | |
package | Package name | |
module | Module name | |
class | Class name | |
method | Method name | |
threadid | Thread Id | |
contenttype | Content type | |
content | Content | |
all | All details |
Supported filter names are:
exclude-package | Exclude a package specified in the value | |
exclude-module | Exclude a module specified in the value | |
exclude-class | Exclude a class specified in the value | |
exclude-method | Exclude a method specified in the value | |
include-package | Include a package specified in the value | |
include-module | Include a module specified in the value | |
include-class | Include a class specified in the value | |
include-method | Include a method specified in the value |
none | No flush (caching only) | |
immediate | Immediate flush (real-time logging) | |
maxcount | Flush cached entries upon reaching LogMaxEventCount entries in the cache. |
Supported values are:
none | None (by default) | |
fatal | Severe errors that cause premature termination. | |
error | Other runtime errors or unexpected conditions. | |
warning | Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". | |
info | Interesting runtime events (startup/shutdown). | |
debug | Detailed information on flow of through the system. | |
trace | More detailed information. |
The default value of this setting is 100.
none | No rotation | |
deleteolder | Delete older entries from the cache upon reaching LogMaxEventCount | |
keepolder | Keep older entries in the cache upon reaching LogMaxEventCount (newer entries are discarded) |
Supported Values:
certificate | Enables caching of certificates. |
crl | Enables caching of Certificate Revocation Lists (CRLs). |
ocsp | Enables caching of OCSP (Online Certificate Status Protocol) responses. |
Example (default value):
PKICache=certificate,crl,ocsp
In this example, the component caches certificates, CRLs, and OCSP responses.
The default value is an empty string - no cached PKI data is stored on disk.
Example:
PKICachePath=C:\Temp\cache
In this example, the cached PKI data is stored in the C:\Temp\cache directory.
Supported values are:
none | No static DNS rules (default) | |
local | Local static DNS rules | |
global | Global static DNS rules |
This setting only applies to certificates originating from a Windows system store.
The property accepts comma-separated values where the first descriptor name is used when the OID is mapped, and subsequent values act as aliases for parsing.
Syntax:
Config("XMLRDNDescriptorName[OID]=PrimaryName,Alias1,Alias2");
Where:
OID: The Object Identifier from the certificate's IssuerRDN or SubjectRDN that you want to map.
PrimaryName: The main descriptor name used in the XML signature when the OID is encountered.
Alias1, Alias2, ...: Optional alternative names recognized during parsing.
Usage Examples:
Map OID 2.5.4.5 to SERIALNUMBER:
Config("XMLRDNDescriptorName[2.5.4.5]=SERIALNUMBER");
Map OID 1.2.840.113549.1.9.1 to E, with aliases EMAIL and EMAILADDRESS:
Config("XMLRDNDescriptorName[1.2.840.113549.1.9.1]=E,EMAIL,EMAILADDRESS");
Trappable Errors (HashFunction Component)
HashFunction Errors
1048577 | Invalid parameter (SB_ERROR_INVALID_PARAMETER) |
1048578 | Invalid configuration (SB_ERROR_INVALID_SETUP) |
1048579 | Invalid state (SB_ERROR_INVALID_STATE) |
1048580 | Invalid value (SB_ERROR_INVALID_VALUE) |
1048581 | Private key not found (SB_ERROR_NO_PRIVATE_KEY) |
1048582 | Cancelled by the user (SB_ERROR_CANCELLED_BY_USER) |
1048583 | The file was not found (SB_ERROR_NO_SUCH_FILE) |
1048584 | Unsupported feature or operation (SB_ERROR_UNSUPPORTED_FEATURE) |
1048585 | General error (SB_ERROR_GENERAL_ERROR) |