[英]Python, OpenSSL: self-signed certificate generation
from cryptography.hazmat.primitives.asymmetric import rsa
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
backend=default_backend()
)
public_key = private_key.public_key()
I'm a beginner in cryptography and I have used the python code above to generate a private and a public key. 我是密码学的初学者,并且我已经使用上面的python代码生成了私钥和公钥。 I'm using the public key to encrypt a password.
我正在使用公共密钥来加密密码。
My question is, how would I password-protect the private key using the self-signed X.509 certificate using openssl tool? 我的问题是,如何使用使用openssl工具的自签名X.509证书对私钥进行密码保护?
I don't think you need to encrypt the Private Key using the self-signed X.509 certificate. 我认为您不需要使用自签名X.509证书对私钥进行加密。 Private Keys are encrypted using pass-phrase.
私钥使用密码短语加密。
You can use the below code snippet to achieve the same: 您可以使用下面的代码片段实现相同的目的:
from cryptography.hazmat.primitives import serilization
key.private_bytes(encoding=serialization.Encoding.PEM,
format = serialization.PrivateFormat.TraditionalOpenSSL,
encryption_algorithm = serialization.BestAvailableEncryption(user_pass))
user_pass
is the passphrase with which you wish to encrypt the private key. user_pass
是您希望用来加密私钥的密码短语。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.