如何使用加密库库加载和签名证书签名请求
我生成了一个证书签名请求(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_certificate
,dump_certificate_request
,load> loads_certificate
和load_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_certificate
和dump_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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论