简体   繁体   English

使用 python 从私钥获取公钥 OpenSSL

[英]get public key from private key with python OpenSSL

Well, I generate a private key with pyOpenSSL as follows:好吧,我用 pyOpenSSL 生成一个私钥,如下所示:

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. 没有做你想要的,然后它看起来不像pyOpenSSL支持公钥转储。 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.使用方法dump_publickey你可以得到你想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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