简体   繁体   English

我们如何使用python的密码库从私钥(受密码保护)中检索公钥?

[英]How can we retrieve public key from private key ( protected with passphrase ) using python's Cryptography library?

I want to use python's Cryptography library to get public key from private key(which could be protected by passphrase also). 我想使用python的密码学库从私钥中获取公钥(也可以通过密码保护)。 How can I do that similar to Python's CryptoDome library ? 我该如何做类似于Python的CryptoDome库

This should work for you: 这应该为您工作:

key_file = open('key.text', 'rb')
private_key = serialization.load_pem_private_key(
    key_file.read(),
    password=None,
    backend=default_backend()
    )
public_key = private_key.public_key()

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

相关问题 我们如何以编程方式从受密码保护的私钥中获取公钥而不创建SSH连接? - How can we programatically get public key from passphrase protected private key without creating an SSH connection? 如何使用Python的加密模块加载RSA公钥 - How to load a RSA public key using Python's cryptography module 如何使用Python2中的“加密”库从证书中打印公钥? - How to print public key from certificates using “cryptography” library in Python2? 使用 python 的加密模块反序列化公钥 - Deserializing public key with python's cryptography module 如何使用密码学python模块加载openssh私钥? - How to load openssh private key using cryptography python module? 如何从python中的公共字节或公共数字恢复EC公钥(加密模块) - How to restore a EC public key from public bytes or public numbers in python (cryptography module) 使用密码学库在 Python 中生成椭圆曲线私钥 - Generating Elliptic Curve Private Key in Python with the cryptography library 如何使用 Fabric 和 fabfile 解密受密码保护的 SSH 密钥? - How to decrypt passphrase-protected SSH key using Fabric and fabfile? 如何使用 python 中的公钥验证私钥 - How to validate a private key using a public key in python 如何使用 Python 从已知私钥生成以太坊公钥 - How do I generate an Ethereum public key from a known private key using Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM