我想使用公共密钥生成一个openSSL :: Pkey,但是我收到以下错误消息“ OpenSSL :: PKey :: RSAError:PUB密钥或PRIV密钥:嵌套asn1错误”
这是公钥:
----- BEGIN公钥----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAttI6ImgD74PhHWVqnrqSOmStboplyL02DB3 / nc2iyDdYLzXoBIQN + NPMBPlsZlEKuKjsg5Ycfp6VjcmncM3CH9MGIr + Lmbj1HZmO / jJGJ84RPhzYOiZuElzs3seIcOtOa3BpFeqRsXJlrf1IVBKVU3erka5ACLVyrsjmp / VXMx5QjPD0qXARMGb6rDewTkyg3pGz07Y7rZgXkTl54ase + XaPegOankxdEQhVjPdrk7eSlIQS5Ni7FAcSyTOtYoPgiP7W0PolOMHvpFg96CHjc8V8xDsFdh0wbHd49WcKxiJMIfL65VUIW5aob9fw05a5FczyASa0iNtRiICy / QnCqQIDAQAB ----- END公钥-----
这是生成错误的代码
OpenSSL::PKey::RSA.new (Base64.decode64(public_key))
任何人都知道如何修复它,并且可以告诉您密钥出了什么问题。谢谢
答案 0 :(得分:0)
BEGIN PUBLIC KEY
和END PUBLIC KEY
应该放在单独的行上。工作示例:
require "openssl"
key = "-----BEGIN PUBLIC KEY-----\n" \
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAttI6ImgD74PhHWVqnrqSOmStboplyL02DB3/nc2iyDdYLzXoBIQN+NPMBPlsZlEKuKjsg5Ycfp6VjcmncM3CH9MGIr+Lmbj1HZmO/jJGJ84RPhzYOiZuElzs3seIcOtOa3BpFeqRsXJlrf1IVBKVU3erka5ACLVyrsjmp/VXMx5QjPD0qXARMGb6rDewTkyg3pGz07Y7rZgXkTl54ase+XaPegOankxdEQhVjPdrk7eSlIQS5Ni7FAcSyTOtYoPgiP7W0PolOMHvpFg96CHjc8V8xDsFdh0wbHd49WcKxiJMIfL65VUIW5aob9fw05a5FczyASa0iNtRiICy/QnCqQIDAQAB\n" \
"-----END PUBLIC KEY-----"
p OpenSSL::PKey::RSA.new(key)