ciphers.diffie_hellman

Attributes

primes

Classes

DiffieHellman

Class to represent the Diffie-Hellman key exchange protocol

Module Contents

class ciphers.diffie_hellman.DiffieHellman(group: int = 14)

Class to represent the Diffie-Hellman key exchange protocol

>>> alice = DiffieHellman()
>>> bob = DiffieHellman()
>>> alice_private = alice.get_private_key()
>>> alice_public = alice.generate_public_key()
>>> bob_private = bob.get_private_key()
>>> bob_public = bob.generate_public_key()
>>> # generating shared key using the DH object
>>> alice_shared = alice.generate_shared_key(bob_public)
>>> bob_shared = bob.generate_shared_key(alice_public)
>>> assert alice_shared == bob_shared
>>> # generating shared key using static methods
>>> alice_shared = DiffieHellman.generate_shared_key_static(
...     alice_private, bob_public
... )
>>> bob_shared = DiffieHellman.generate_shared_key_static(
...     bob_private, alice_public
... )
>>> assert alice_shared == bob_shared
generate_public_key() str
generate_shared_key(other_key_str: str) str
static generate_shared_key_static(local_private_key_str: str, remote_public_key_str: str, group: int = 14) str
get_private_key() str
is_valid_public_key(key: int) bool
static is_valid_public_key_static(remote_public_key_str: int, prime: int) bool
__private_key
generator
prime
ciphers.diffie_hellman.primes