hash.py

Contains functions for hashing values with use of HMAC or without.

An hash is created as:
hash_algorithm$salt$hashed_value
an HMAC is created as:
hash_algorirthm$hashed_value

All values are default stored as base64

Class and function definitions:

exception core.encryption.hash.HashException[source]

Bases: exceptions.Exception

This exception is thrown when the hash algorithm is unknown.

core.encryption.hash.check_hmac(secret, password, hmac_base64)[source]

Checks whether the hmac(password, secret) is the same as the hmac_base64.

Args:
  • secret: the key to use
  • password: the value to hash.
  • hmac_base64: base64 representation in hash_algorirthm$hashed_value format
Returns:
True/False
Raises:
HashException: HMAC algorithm unknown
core.encryption.hash.check_hash(password, hash_base64)[source]

Checks whether the hash(password) is the same as the hmac_base64.

Args:
  • password: the value to hash.
  • hmac_base64: base64 representation in hash_algorirthm$salt$hashed_value format
Returns:
True/False
Raises:
HashException: hash algorithm unknown
core.encryption.hash.create_hmac(secret, password, hasher=default_hasher, iterations= default_iterations)[source]

Create a hmac from secret and password with ability to set the hasher and number of iterations.

Args:
  • secret: the key to use
  • password: the value to hash.
  • hasher: override default hasher
  • iterations: override default iterations.
Returns:
hash_algorirthm$hashed_value in base64 format
Raises:
HashException: HMAC algorithm unknown
core.encryption.hash.create_hash(password, salt, hasher=default_hasher, iterations= default_iterations)[source]

Create a hash of password using salt, hasher and iterations

Args:
  • password: the value to hash.
  • salt: the salt value.
  • hasher: override default hasher
  • iterations: override default iterations.
Returns:
hash_algorirthm$salt$hashed_value in base64 format
Raises:
HashException: Hash algorithm unknown
core.encryption.hash.do_hash(password, hasher)[source]

Shortcut for crypto hashing function

Args:
  • password: the value to hash.
  • hasher: override default hasher
Returns:
password hashed by hasher
core.encryption.hash.do_hmac_hash(secret, password, hasher)[source]

Shortcut for hmac function

Args:
  • secret: the key to use
  • password: the value to hash.
  • hasher: the hasher to use
Returns:
password hashed by hasher with HMAC