OpenSSL - Neither PUB key nor PRIV key:: nested asn1 error

前端 未结 4 528
名媛妹妹
名媛妹妹 2021-01-05 08:48

I am trying to initialize OpenSSL::PKey::RSA using a public key, and it is not working.

Following is the key pair:

-----BEGIN RSA PRIVATE KEY-----
MI         


        
相关标签:
4条回答
  • 2021-01-05 09:21

    Following this link http://skim.la/2012/01/16/rsa-public-key-interoperability-between-ruby-and-android/ I had more success this way.

    require 'openssl'
    require 'base64'
    
    public_key = "MIIBCgKCAQEA20O377QEiZvPsj14LKl2xO23iirJB5WDTVjeab1cIOJu1vbV+Pdwl1Bov8m896ZG4K0S/qvfJcdHLovr2WJ+o2maK1XZCNy8lA" +
      "zIPzZrj/yDZAB2GSjR3in1lQRQPtWjIOdB8Cy2FGybEstIkpf8MD3XMWp5g8BtdOv43ekjBuTiGGLlPRG0+IiazjHlWjyl6DU9x9m2Jxks0H6YZud6zf4s9Q6" +
      "9vPUYgOZXWs7IghxqrVGE5mWxoRudsDFhLYP706+IrSxGOf5fE0/8fjtzj/eJayCLmkUWq/xsts5tBAbwsX5xKdk8iD0OU2qOEbVuiYmehEiJnvO2vyd+t76C" +
      "xwIDAQAB"
    
    rsa_public_key = OpenSSL::PKey::RSA.new(Base64.decode64(public_key))
    
    0 讨论(0)
  • 2021-01-05 09:24

    I was facing the same issue and I tried lot of different solutions given across internet. But the actual problem was with the key that I was providing. The formatting of the key should be proper. There should not be any extra character or \n , \t.

    I hope this might help you. So, please check your key once again.

    0 讨论(0)
  • 2021-01-05 09:28

    Same day I was stuck with the same issue, changing passphrase might help you. So verify your passphrase and change it in notification class.I hope this might help you.

    I have changed in file app/jobs/notification_job.rb

    certificate: Rails.root.join('Your Pem File Name Goes Here'),# required
                    passphrase:  "PASSPHRASE GOES HERE",              # optional
                    gateway:     "gateway.push.apple.com", # optional; See note below.
                    # gateway:     "gateway.sandbox.push.apple.com", # optional; See note below.
    
    0 讨论(0)
  • 2021-01-05 09:38

    It looks like what you've got there should work only the public key itself isn't valid. Maybe you mangled them at some point by adding or removing an extra character by accident. You can test this key out and should see it work out

    public_key = "-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAoxi2V0bSKqAqUtoQHxWkOPnErCS541r6/MOSHmKOd6VSNHoBbnas\nZRQSDUTbffB6C++DbmBCOHmvzYORD0ZWYgyMcgbYJD48Z2fe0nm+WMYN5u8DPnTP\nvf8b/rJBxGF0dsaoFAWlB81tTnKFCxAbCSgfmQt+Vd4qupGZ5gGu9uoKlaPjmYuA\nIxIjUMcu3dov7PQ+PZIvdkM0fiz8YIl8zo+iWWyI2s6/XLoZJ4bYs2YJHZDf6biU\nsZhs8xqh/F6qlcRt3Ta25KMa0TB9zE3HHmqA/EJHFubWFRCrQqpboB0+nwCbmZUl\nhaxA79FRvYtORvFAoncoFD4tq3rGXcUQQwIDAQAB\n-----END RSA PUBLIC KEY-----\n"
    
    OpenSSL::PKey::RSA.new(public_key)
    

    I generated my key by first running the linux command for generating an openSSH key pair

    $  ssh-keygen -t rsa -b 1024
    

    Then I converted OpenSSH style public key to an OpenSSL style key (PEM format), storing it in a file called 'pem'.

    $  ssh-keygen -f testing_rsa.pub  -e -m pem > pem
    
    0 讨论(0)
提交回复
热议问题