如何使用加密库库加载和签名证书签名请求

发布于 2025-01-23 12:25:13 字数 1722 浏览 3 评论 0原文

我生成了一个证书签名请求(CSR),

from OpenSSL import crypto

cert = crypto.X509()
cert.get_subject().C = "US"
cert.get_subject().ST = "Minnesota"
cert.get_subject().L = "Minnetonka"
cert.get_subject().O = "my company"
cert.get_subject().OU = "my organization"
cert.get_subject().CN = "aaa.com"

然后保存了它。

# Save the csr
name = 'cert.crt'
pem = crypto.dump_certificate(crypto.FILETYPE_PEM, cert)
with open(name, 'wb') as f:
    f.write(pem)

我想加载CSR,签名,然后保存。

这是我的尝试

# Read it
with open(name, 'rb') as pem:
    cert_pem = pem.read()

下一步可能是使用加密库。 ,我尝试使用functions dump_certificatedump_certificate_requestload> loads_certificateload_certificate_request

# Load
load_cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_pem)

因此 我遇到了错误。
load_certificate创建错误:

Error: [('asn1 encoding routines', 'asn1_item_embed_d2i', 'field missing'), ('asn1 encoding routines', 'asn1_template_noexp_d2i', 'nested asn1 error'), ('asn1 encoding routines', 'asn1_template_noexp_d2i', 'nested asn1 error'), ('PEM routines', 'PEM_ASN1_read_bio', 'ASN1 lib')]

load_certificate_request创建错误:

Error: [('PEM routines', 'get_name', 'no start line')]

dump_cert_certificatedump_certificate_request创建错误:创建错误:创建错误:创建错误:

AttributeError: 'bytes' object has no attribute '_x509'

我如何加载企业社会责任,准备签名?

I generated a certificate signing request (csr)

from OpenSSL import crypto

cert = crypto.X509()
cert.get_subject().C = "US"
cert.get_subject().ST = "Minnesota"
cert.get_subject().L = "Minnetonka"
cert.get_subject().O = "my company"
cert.get_subject().OU = "my organization"
cert.get_subject().CN = "aaa.com"

Then saved it.

# Save the csr
name = 'cert.crt'
pem = crypto.dump_certificate(crypto.FILETYPE_PEM, cert)
with open(name, 'wb') as f:
    f.write(pem)

I would like to load the csr, sign it, and then save it.

Here is my try

# Read it
with open(name, 'rb') as pem:
    cert_pem = pem.read()

The next step would probably be to load the csr using a build in function of the crypto libray. Hence, I tried it with the functions dump_certificate, dump_certificate_request, load_certificate and load_certificate_request, using them as follows:

# Load
load_cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_pem)

But I get Errors.
The load_certificate creates the error:

Error: [('asn1 encoding routines', 'asn1_item_embed_d2i', 'field missing'), ('asn1 encoding routines', 'asn1_template_noexp_d2i', 'nested asn1 error'), ('asn1 encoding routines', 'asn1_template_noexp_d2i', 'nested asn1 error'), ('PEM routines', 'PEM_ASN1_read_bio', 'ASN1 lib')]

whereas the load_certificate_request creates the error:

Error: [('PEM routines', 'get_name', 'no start line')]

The dump_certificate and the dump_certificate_request create the error:

AttributeError: 'bytes' object has no attribute '_x509'

How could I load the csr, to be ready for the signature ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文