pairid module
Library of cryptographic key generation and data preparation procedures associated with the PAIR protocol.
The example below illustrates how the functions can be used in conjunction with one another.
>>> ks = key_salt()
>>> ka = key_commutative()
>>> kb = key_commutative()
>>> ciphertext_s = salt(ks, 'alice@example.com')
>>> ciphertext_sa = encrypt(ka, ciphertext_s)
>>> ciphertext_sab = encrypt(kb, ciphertext_sa)
>>> decrypt(ka, ciphertext_sab) == encrypt(kb, ciphertext_s)
True
- key_commutative() bytes[source]
Generate a secret commutative encryption key.
>>> isinstance(key_commutative(), bytes) True
- salt(salt: bytes, plaintext: str) bytes[source]
Salt a string using a secret salt.
>>> kc = key_salt() >>> ciphertext = salt(kc, 'alice@example.com') >>> isinstance(ciphertext, bytes) and len(ciphertext) == 32 True
- encrypt(key: bytes, plaintext: Union[str, bytes]) bytes[source]
Encrypt a string using a secret commutative key.
>>> kc = key_commutative() >>> ciphertext = encrypt(kc, 'alice@example.com') >>> isinstance(ciphertext, bytes) and len(ciphertext) == 32 True
- decrypt(key: bytes, ciphertext: bytes) bytes[source]
Remove a layer of encryption (corresponding to they supplied secret commutative key) from a ciphertext.
>>> ka = key_commutative() >>> kb = key_commutative() >>> ciphertext = encrypt(ka, 'alice@example.com') >>> ciphertext = encrypt(kb, ciphertext) >>> decrypt(ka, ciphertext) == encrypt(kb, 'alice@example.com') True