SecureBlackbox 2020 Python Edition

Questions / Feedback?

HashFunction Class

Properties   Methods   Events   Configuration Settings   Errors  

The HashFunction class implements a wide variety of algorithms for message hashing.

Syntax

class secureblackbox.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 update_file and update_stream 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 output_encoding 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.

algorithmThe hash algorithm to use when hashing data.
json_key_header_paramsContains key header parameters.
json_protected_headerProvides access to the header being protected.
json_unprotected_headerProvides access to the unprotected part of the header.
json_unprotected_header_paramsContains unprotected header parameters.
key_algorithmThe algorithm of the cryptographic key.
key_bitsThe length of the key in bits.
key_exportableReturns True if the key is exportable (can be serialized into an array of bytes), and False otherwise.
key_handleAllows to get or set a 'handle', a unique identifier of the underlying property object.
key_idProvides access to a storage-specific key identifier.
key_ivThe initialization vector (IV) of a symmetric key.
key_keyThe byte array representation of the key.
key_nonceA nonce value associated with a key.
key_privateReturns True if the object hosts a private key, and False otherwise.
key_publicReturns True if the object hosts a public key, and False otherwise.
key_subjectReturns the key subject.
key_symmetricReturns True if the object contains a symmetric key, and False otherwise.
key_validReturns True if this key is valid.
output_encodingThe 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.

configSets or retrieves a configuration setting.
finishCompletes the hash and returns the resulting message digest.
hashCalculates a message digest over a byte array.
hash_fileCalculates a message digest over data contained in a file.
hash_streamCalculates a message digest over data contained in a stream.
resetResets the hash function context.
updateFeeds a chunk of data to the hash function.
update_fileFeeds the contents of a file to the hash function.
update_streamFeeds 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.

on_errorInforms about errors during cryptographic operations.
on_notificationThis 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.

TempPathPath for storing temporary files.
CheckKeyIntegrityBeforeUseEnables or disable private key integrity check before use.
CookieCachingSpecifies whether a cookie cache should be used for HTTP(S) transports.
CookiesGets or sets local cookies for the class (supported for HTTPClient, RESTClient and SOAPClient only).
DefDeriveKeyIterationsSpecifies the default key derivation algorithm iteration count.
EnableClientSideSSLFFDHEEnables or disables finite field DHE key exchange support in TLS clients.
GlobalCookiesGets or sets global cookies for all the HTTP transports.
HttpUserAgentSpecifies the user agent name to be used by all HTTP clients.
LogDestinationSpecifies the debug log destination.
LogDetailsSpecifies the debug log details to dump.
LogFileSpecifies the debug log filename.
LogFiltersSpecifies the debug log filters.
LogFlushModeSpecifies the log flush mode.
LogLevelSpecifies the debug log level.
LogMaxEventCountSpecifies the maximum number of events to cache before further action is taken.
LogRotationModeSpecifies the log rotation mode.
MaxASN1BufferLengthSpecifies the maximal allowed length for ASN.1 primitive tag data.
MaxASN1TreeDepthSpecifies the maximal depth for processed ASN.1 trees.
OCSPHashAlgorithmSpecifies the hash algorithm to be used to identify certificates in OCSP requests.
UseOwnDNSResolverSpecifies whether the client classes should use own DNS resolver.
UseSharedSystemStoragesSpecifies whether the validation engine should use a global per-process copy of the system certificate stores.
UseSystemOAEPAndPSSEnforces or disables the use of system-driven RSA OAEP and PSS computations.
UseSystemRandomEnables or disables the use of the OS PRNG.

Copyright (c) 2022 /n software inc. - All rights reserved.
SecureBlackbox 2020 Python Edition - Version 20.0 [Build 8165]