Hashing¶
- class chepy.modules.hashing.Hashing(*data)¶
- bcrypt_compare(hash: str) HashingT ¶
Compare Bcrypt hash
Tests whether the provided hash matches the given string at init.
- Parameters
hash (str) – Required. brypt hash
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("abc") >>> c.bcrypt_compare("$2a$10$SpXMRnrQ4IQqC710xMHfAu0BBr4nJkuPqDvzhiAACnykgn87iE2S2") True
- bcrypt_hash(rounds: int = 10) HashingT ¶
Get Bcrypt hash
- Parameters
rounds (int, optional) – rounds of hashing, by default 10
- Returns
The Chepy object.
- Return type
- blake_2b(bits: int = 256, key: bytes = '') HashingT ¶
Get Balke-2b hash
- Parameters
bits (int, optional) – Number of digest bits, by default 256
key (bytes, optional) – Encryption secret key, by default ‘’
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").blake_2b(bits=128, key="key").out "6d2e4cba3bc564e02d1a76f585a6795d"
- blake_2s(bits: int = 256, key: bytes = '') HashingT ¶
Get Blake-2s hash
- Parameters
bits (int, optional) – Number of digest bits, by default 256
key (bytes, optional) – Encryption secret key, by default ‘’
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").blake_2s(bits=128, key="key").out "4e33cc702e9d08c28a5e9691f23bc66a"
- crc32_checksum() HashingT ¶
Get CRC32 checksum
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("a").crc32_checksum().out "e8b7be43"
- derive_pbkdf2_key(password: Union[str, bytes], salt: Union[str, bytes], key_size: int = 256, iterations: int = 1000, hash_type: Literal['md5', 'sha1', 'sha256', 'sha512'] = 'sha1', hex_salt: bool = True, show_full_key: bool = False)¶
Derive a PBKDF2 key
- Parameters
password (Union[str, bytes]) – Password
salt (Union[str, bytes]) – Salt
key_size (int, optional) – Key size. Defaults to 256.
iterations (int, optional) – Number of iterations. Defaults to 1000.
hash_type (Literal[, optional) – Hash type. Defaults to “sha1”.
hex_salt (bool, optional) – If salt is in hex format. Defaults to True.
show_full_key (bool, optional) – Show AES256 64 bit key only. Defaults to False.
- Raises
TypeError – If hash type is not one of md5, sha1, sha256, sha512
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(".").derive_pbkdf2_key("mR3m", "d9016d44c374f5fb62604683f4d61578").o[:10] "7c8898f222"
- hmac_hash(key: bytes = b'', digest: str = 'sha1') HashingT ¶
Get HMAC hash
HMAC hash the state
Keyed-Hash Message Authentication Codes (HMAC) are a mechanism for message authentication using cryptographic hash functions.
- Parameters
key (bytes, optional) – Starting key for the hash, by default b’’
digest (str, optional) – The digest type, by default “sha1”. Possible values are md5, sha1, sha256 and sha512
- Returns
The Chepy object.
- Return type
- Raises
TypeError – If key is not in bytes
TypeError – If not a valid/allowed digest type
- md5() HashingT ¶
Get MD5 hash
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").md5().out "7fc56270e7a70fa81a5935b72eacbe29"
- password_hashing(format: str, **kwargs: Any) HashingT ¶
Hash the state with various password hashing algorithms
- Parameters
format (str) – Hash state with password algorithms
- Returns
The Chepy object.
- Return type
- scrypt_hash(salt: str = '', key_length: int = 64, N: int = 14, r: int = 8, p: int = 1)¶
Get Scrypt hash
- Parameters
salt (str, optional) – A string of characters that modifies the hash. Defaults to “”.
key_length (int, optional) – number of bytes to use when autogenerating new salts. Defaults to 64.
N (int, optional) – CPU/memory cost parameter. Defaults to 14.
r (int, optional) – The blocksize parameter. Defaults to 8.
p (int, optional) – Parallelization parameter;. Defaults to 1.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("abc").scrypt_hash(salt="", key_length=16).out "f352f3374cf4e344dde4108b96985248"
- sha1() HashingT ¶
Get SHA1 hash
The SHA (Secure Hash Algorithm) hash functions were designed by the NSA. SHA-1 is the most established of the existing SHA hash functions and it is used in a variety of security applications and protocols. However, SHA-1’s collision resistance has been weakening as new attacks are discovered or improved.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").sha1().out "6dcd4ce23d88e2ee9568ba546c007c63d9131c1b"
- sha2_224() HashingT ¶
Get SHA2-224 hash
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").sha2_224().out "5cfe2cddbb9940fb4d8505e25ea77e763a0077693dbb01b1a6aa94f2"
- sha2_256() HashingT ¶
Get SHA2-256 hash
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").sha2_256().out "559aead08264d5795d3909718cdd05abd49572e84fe55590eef31a88a08fdffd"
- sha2_512() HashingT ¶
Get SHA2-512 hash
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").sha2_512().out 21b4f4bd9e64ed355c3eb676a28ebedaf6d8f17bdc365995b319097153044080516bd083bfcce66121a3072646994c8430cc382b8dc543e84880183bf856cff5
- sha2_512_truncate(truncate: int = 256) HashingT ¶
Get SHA2-512/bits hash
- Parameters
truncate (int, optional) – The bits to truncate by. Defaults to 256
- Returns
The Chepy object.
- Return type
- shake_128(size: int = 64) HashingT ¶
Get Shake-128 hash
Shake is an Extendable Output Function (XOF) of the SHA-3 hash algorithm, part of the Keccak family, allowing for variable output length/size.
- Parameters
size (int, optional) – How many bytes to read, by default 64
- Returns
The Chepy object.
- Return type
- shake_256(size: int = 64) HashingT ¶
Get Shake-256 hash
Shake is an Extendable Output Function (XOF) of the SHA-3 hash algorithm, part of the Keccak family, allowing for variable output length/size.
- Parameters
size (int, optional) – How many bytes to read, by default 64
- Returns
The Chepy object.
- Return type