Skip to main content

A Pythonic implementation of the Diffie-Hellman key exchange protocol

Project description


Travis CI PyPI version

The Python Diffie-Hellman key exchange library.


from diffiehellman.diffiehellman import DiffieHellman

alice = DiffieHellman()
bob = DiffieHellman()

alice.generate_public_key()    # automatically generates private key

alice.generate_shared_secret(bob.public_key, echo_return_key=True)
bob.generate_shared_secret(alice.public_key, echo_return_key=True)


pip install diffiehellman


  • Implements Diffie-Hellman key exchange
  • Pretty fast
  • Adjustable key size
  • Includes primes for groups 5 and 14-18
  • Currently works only with Python 3 (requires ssl). An OpenSSL compatible version is in the works.

Code of Misconduct

By using this package, you pledge to use it for good, not for evil. In particular, you pledge never to use this code to limit the human mind or its natural rights, in particular freedom of expression.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moat-lib-diffiehellman- (17.0 kB view hashes)

Uploaded Source

Built Distribution

moat_lib_diffiehellman- (9.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page