Next | Previous

hash

This module provides a framework for cryptographic and non-cryptographic encryption.

Examples,

%> import hash
%> 
%> hash.md5('Hello, World')
'82bb413746aee42f89dea2b59614f9ef'
%> 
%> hash.sha256('Hello, World')
'03675ac53ff9cd1535ccc7dfcdfa2c458c5218371f418dc136f2d19ac1fbe8a5'
%> 
%> hash.siphash('mykey', 'Hello, World')
'd8e830a590c92b4c'
%> 
%> hash.hmac_sha256('mykey', 'Hello, World')
'61035d3d2119ffdfd710913bf4161d5fba1c2d9431f7de7ef398d359eb1d2481'
%> 
%> hash.hmac_sha256(bytes([10, 11, 12]), 'My secure text!')
'd782079145a3476fd4e018d44dd024034fa91f626f7f30f2009200c5ac757723'

Functions

hash.hash(value)

Returns the hash of a value as used in a dictionary underlying implementation. A class may override the result of this function by implementing the to_hash decorator

  • @params:
    • any value
  • @returns: number
hash.adler32(str, value)

Returns the adler32 value of the given string or bytes If value is given, it is used as the base value of the adler32 computation. Else, 1 is used.

  • @params:
    • string|bytes str
    • number? value
  • @returns: number
hash.crc32(str, value)

Returns the crc32 value of the given string or bytes If value is given, it is used as the base value of the crc32 computation. Else, 0 is used.

  • @params:
    • string|bytes str
    • number? value
  • @returns: number
hash.md2(str)

Returns the md2 hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.md4(str)

Returns the md4 hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.md5(str)

Returns the md5 hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.md5_file(file)

Returns the md5 hash of the given file.

  • @params:
    • file file
  • @returns: string
hash.sha1(str)

Returns the sha1 hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.sha224(str)

Returns the sha224 hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.sha256(str)

Returns the sha256 hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.sha384(str)

Returns the sha384 hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.sha512(str)

Returns the sha512 hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.fnv1(str)

Returns the 32 bit fnv1 hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.fnv1_64(str)

Returns the 64 bit fnv1 hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.fnv1a(str)

Returns the 32 bit fnv1a hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.fnv1a_64(str)

Returns the 64 bit fnv1a hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.whirlpool(str)

Returns the whirlpool hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.snefru(str)

Returns the Snefru cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.siphash(key, str)

Returns the SipHash cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.gost(str)

Returns the Gost cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes str
  • @returns: string
hash.hmac(method, key, str)

Computes an HMAC with the key and str using the given method.

  • @params:
    • function method
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.hmac_md2(key, str)

Returns the HMAC-MD2 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.hmac_md4(key, str)

Returns the HMAC-MD4 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.hmac_md5(key, str)

Returns the HMAC-MD5 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.hmac_sha1(key, str)

Returns the HMAC-SHA1 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.hmac_sha224(key, str)

Returns the HMAC-SHA224 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.hmac_sha256(key, str)

Returns the HMAC-SHA256 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.hmac_sha384(key, str)

Returns the HMAC-SHA384 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.hmac_sha512(key, str)

Returns the HMAC-SHA512 cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.hmac_whirlpool(key, str)

Returns the HMAC-WHIRLPOOL cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.hmac_snefru(key, str)

Returns the HMAC-SNEFRU cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string
hash.hmac_gost(key, str)

Returns the HMAC-GOST cryptographic hash of the given string or bytes.

  • @params:
    • string|bytes key
    • string|bytes str
  • @returns: string