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
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