证书到证书的pem无法正常工作:嵌套asn1错误 [英] Certificate to pem to certificate not working: nested asn1 error

查看:579
本文介绍了证书到证书的pem无法正常工作:嵌套asn1错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从字符串创建证书.为什么这不起作用:

I want to create a certificate from a string. Why does this not work:

OpenSSL::X509::Certificate.new(OpenSSL::X509::Certificate.new.to_pem)

它返回:OpenSSL::X509::CertificateError: nested asn1 error

推荐答案

所以我自己得到了答案.证书至少需要以下信息:

So I got the answer myself. The certificate needs at least these information:

cert = OpenSSL::X509::Certificate.new
cert.version = 2
cert.serial = 0
cert.not_before = Time.now
cert.not_after = Time.now + 3600
cert.public_key = key.public_key
cert.sign key, OpenSSL::Digest::SHA1.new

那么这是可能的:

OpenSSL::X509::Certificate.new(cert.to_pem) =>返回

这篇关于证书到证书的pem无法正常工作:嵌套asn1错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆