是什么原因导致"无论是PUB键也不PRIV键::嵌套ASN1错误"建设红宝石公钥是什么时候? [英] What causes "Neither PUB key nor PRIV key:: nested asn1 error" when building a public key in ruby?
问题描述
在通过传递一个.pem文件使用OpenSSL的:: PKEY :: RSA模块构建公共密钥,什么是响应的原因:
的OpenSSL :: PKEY :: RSAError:无论PUB键也不PRIV键::嵌套ASN1错误
从/Users/Matt/projects/placepop/lib/apn.rb:48:in`初始化
从/Users/Matt/projects/placepop/lib/apn.rb:48:in`新'
从/Users/Matt/projects/placepop/lib/apn.rb:48:in`开放
从(IRB):1
下面是源:
证书= File.join(RAILS_ROOT,'配置','APNS','沙箱-cert.pem)
APN_CONFIG = {:快递=> {
:主机=> gateway.sandbox.push.apple.com',
:证书=>证书,
:密码=> ,
:端口=> 2195},
:反馈= GT; {
:主机=> feedback.sandbox.push.apple.com',
:端口=> 2196,
:密码=> ,
:证书=>证书}}
选项= APN_CONFIG [:送货] .merge(选项)
证书= File.read(选项[:证书])
CTX = OpenSSL的SSL :: :: SSLContext.new
ctx.key = OpenSSL的:: PKEY :: RSA.new(CERT,选项[:密码])
ctx.cert = OpenSSL的:: X509 :: Certificate.new(CERT)袜子= TCPSocket.new(选项[:主机],选择[:端口])
SSL = OpenSSL的SSL :: :: SSLSocket.new(袜子,CTX)
ssl.sync =真
ssl.connect
一个PEM文件是不是一个公共密钥,它是一个包含,它的许多领域,公钥之间的base64-CN codeD X509证书。我不知道Ruby或OpenSSL的红宝石模块,但我会找一些函数读取PEM文件和输出X509证书,那么另一个函数提取证书的公钥。
When building a public key using the OpenSSL::PKey::RSA module by passing it a .pem file, what is the cause for a response:
OpenSSL::PKey::RSAError: Neither PUB key nor PRIV key:: nested asn1 error
from /Users/Matt/projects/placepop/lib/apn.rb:48:in `initialize'
from /Users/Matt/projects/placepop/lib/apn.rb:48:in `new'
from /Users/Matt/projects/placepop/lib/apn.rb:48:in `open'
from (irb):1
Here is the source:
cert = File.join(rails_root, 'config', 'apns', 'sandbox-cert.pem')
APN_CONFIG = { :delivery => {
:host => 'gateway.sandbox.push.apple.com',
:cert => cert,
:passphrase => "",
:port => 2195 },
:feedback => {
:host => 'feedback.sandbox.push.apple.com',
:port => 2196,
:passphrase => "",
:cert => cert} }
options = APN_CONFIG[:delivery].merge(options)
cert = File.read(options[:cert])
ctx = OpenSSL::SSL::SSLContext.new
ctx.key = OpenSSL::PKey::RSA.new(cert, options[:passphrase])
ctx.cert = OpenSSL::X509::Certificate.new(cert)
sock = TCPSocket.new(options[:host], options[:port])
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
ssl.sync = true
ssl.connect
A pem file is not a public key, it is a base64-encoded X509 certificate that contains, among its many fields, a public key. I don't know Ruby, or the OpenSSL ruby module, but I would look for some function that reads in PEM files and outputs an X509 certificate, then another function to extract the public key from the certificate.
这篇关于是什么原因导致"无论是PUB键也不PRIV键::嵌套ASN1错误"建设红宝石公钥是什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!