Search code examples
pythonopensslprivatepublic

Python OpenSSL generating public and private key pair


I am having problem finding a command that would generate a public and private key pair using OpenSSL. Could someone show me some example code of this in action.

Thank you


Solution

  • Using the pyOpenSSL bindings:

    OpenSSL.crypto.PKey().generate_key(type, bits)
    

    Generate a public/private key pair of the type type (one of TYPE_RSA and TYPE_DSA) with the size bits.

    Docs