简体   繁体   中英

How do I generate public and private keys with pyOpenSSL?

I can obtain the private key (PEM format), but I'm not sure how to generate the public key:

from OpenSSL import crypto, SSL

key = crypto.PKey()
key.generate_key(crypto.TYPE_RSA, 1024)
priv_key = crypto.dump_privatekey(crypto.FILETYPE_PEM, key)
pub_key = ... ?

According to the pyopenssl docs

pub_key = crypto.dump_publickey(type, key)

where type = The file type (one of :data: FILETYPE_PEM or :data: FILETYPE_ASN1 ).

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM