Pbe class¶
- class crsysapi.Pbe¶
Password-based encryption.
- class PrfAlg¶
PRF algorithms.
- HMAC_SHA1 = 0¶
HMAC-SHA-1 (default)
- HMAC_SHA224 = 6¶
HMAC-SHA-224
- HMAC_SHA256 = 3¶
HMAC-SHA-256
- HMAC_SHA384 = 4¶
HMAC-SHA-384
- HMAC_SHA512 = 5¶
HMAC-SHA-512
- static kdf2(dklen, password, salt, count, prfalg=0)¶
Derive a key of any length from a password using the PBKDF2 algorithm.
- Parameters:
dklen (int) -- Required length of key in bytes
password (str) -- Password
salt (bytes) -- Salt in byte array
count (int) -- Iteration count
prfalg (PrfAlg) -- Algorithm to use in PRF [default = HMAC-SHA-1]
- Returns:
Derived key in byte array.
- Return type:
bytes
Examples
>>> Cnv.tohex(Pbe.kdf2(24, 'password', Cnv.fromhex('78578E5A5D63CB06'), 2048)) 'BFDE6BE94DF7E11DD409BCE20A0255EC327CB936FFE93643'
- static scrypt(dklen, pwdbytes, salt, N, r, p)¶
Derive a key of any length from a password using the SCRYPT algorithm from RFC7914.
- Parameters:
dklen (int) -- Required length of key in bytes
pwdbytes (bytes) -- Password encoded in bytes
salt (bytes) -- Salt in byte array
N (int) -- CPU/Memory cost parameter, a number greater than one and a power of 2.
r (int) -- Block size r.
p (int) -- Parallelization parameter p.
- Returns:
Derived key in byte array.
- Return type:
bytes
Examples
>>> Cnv.tohex(Pbe.scrypt(64, b'password', b'NaCl', 1024, 8, 16)) 'FDBABE1C9D3472007856E7190D01E9FE7C6AD7CBC8237830E77376634B373162' '2EAF30D92E22A3886FF109279D9830DAC727AFB94A83EE6D8360CBDFA2CC0640' >>> Cnv.tohex(Pbe.scrypt(64, b'', b'', 16, 1, 1)) '77D6576238657B203B19CA42C18A0497F16B4844E3074AE8DFDFFA3FEDE21442' 'FCD0069DED0948F8326A753A0FC81F17E8D3E0FB2E0D3628CF35E20C38D18906'