gpt4 book ai didi

python - python crypto 中的发行人替代名称

转载 作者:行者123 更新时间:2023-12-01 09:24:12 25 4
gpt4 key购买 nike

有没有办法在 x509 中使用扩展名创建替代发行者名称?到目前为止我的代码:

from OpenSSL import crypto

def generate_self_signed_cert(cert_dir, is_valid=True):
"""Generate a SSL certificate.

If the cert_path and the key_path are present they will be overwritten.
"""

#Keys
private_key=crypto.load_privatekey(crypto.FILETYPE_PEM,open("/root/Desktop/Key2","rb").read())
public_key=crypto.load_publickey(crypto.FILETYPE_PEM,open("/root/Desktop/Key1","rb").read())
# create a self-signed cert
cert = crypto.X509()
cert.get_subject().C = 't'
cert.get_subject().ST = 't'
cert.get_subject().L = 's'
cert.get_subject().O = 'd'
cert.get_subject().OU = 'g'
cert.get_subject().CN = 'g'
cert.set_serial_number(01)
cert.gmtime_adj_notBefore(0)
cert.gmtime_adj_notAfter(3655555555)
cert.set_issuer(cert.get_subject())
cert.set_pubkey(public_key)
cert.add_extensions([
crypto.X509Extension("basicConstraints", False, "CA:FALSE"),
crypto.X509Extension("keyUsage", True, "Digital Signature, Non Repudiation"),
])

cert.set_version(2)
cert.sign(private_key, 'sha256')


with open(cert_dir+"Cert.cert", 'w+') as fd:
fd.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))



generate_self_signed_cert("/root/Desktop/")

代码运行良好。我只需要添加替代发行人名称。这应该通过扩展来完成,对吗?

最佳答案

好的,这个问题的答案是:

 crypto.X509Extension("issuerAltName",False,"email:"+"test")

关于python - python crypto 中的发行人替代名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50570533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com