get public key from private key with python OpenSSL
Question:
Well, I generate a private key with pyOpenSSL as follows:
from OpenSSL import crypto
k = crypto.PKey()
k.generate_key(crypto.TYPE_RSA, 2048)
print crypto.dump_privatekey(crypto.FILETYPE_PEM, k)
How do I get the public key string from it? I’ve still not found what method of this library does it. Thanks
Answers:
If
cert = crypto.dump_certificate(crypto.FILETYPE_PEM, k)
doesn’t do what you want, then it doesn’t look like pyOpenSSL
supports public key dumping. There is an unmerged branch here that adds that functionality but I can’t claim that it does what is purports.
Updated:
Now it has the method to get public key directly.
key = crypto.PKey()
key.generate_key(crypto.TYPE_RSA, 2048)
publickey_contents = crypto.dump_publickey(crypto.FILETYPE_PEM, key)
with the method dump_publickey
you can get what you want.
Well, I generate a private key with pyOpenSSL as follows:
from OpenSSL import crypto
k = crypto.PKey()
k.generate_key(crypto.TYPE_RSA, 2048)
print crypto.dump_privatekey(crypto.FILETYPE_PEM, k)
How do I get the public key string from it? I’ve still not found what method of this library does it. Thanks
If
cert = crypto.dump_certificate(crypto.FILETYPE_PEM, k)
doesn’t do what you want, then it doesn’t look like pyOpenSSL
supports public key dumping. There is an unmerged branch here that adds that functionality but I can’t claim that it does what is purports.
Updated:
Now it has the method to get public key directly.
key = crypto.PKey()
key.generate_key(crypto.TYPE_RSA, 2048)
publickey_contents = crypto.dump_publickey(crypto.FILETYPE_PEM, key)
with the method dump_publickey
you can get what you want.