ciphers.diffie_hellman ====================== .. py:module:: ciphers.diffie_hellman Attributes ---------- .. autoapisummary:: ciphers.diffie_hellman.primes Classes ------- .. autoapisummary:: ciphers.diffie_hellman.DiffieHellman Module Contents --------------- .. py:class:: 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 .. py:method:: generate_public_key() -> str .. py:method:: generate_shared_key(other_key_str: str) -> str .. py:method:: generate_shared_key_static(local_private_key_str: str, remote_public_key_str: str, group: int = 14) -> str :staticmethod: .. py:method:: get_private_key() -> str .. py:method:: is_valid_public_key(key: int) -> bool .. py:method:: is_valid_public_key_static(remote_public_key_str: int, prime: int) -> bool :staticmethod: .. py:attribute:: __private_key .. py:attribute:: generator :value: 2 .. py:attribute:: prime .. py:data:: primes