Trying to encrypt a text message via command line on OSX Yosomite 10.10.2
Created public .pem
key like this:
ssh-keygen -f ~/.ssh/id_rsa.pub
I had same problem when I was extracting public key from certificate.
openssl x509 -pubkey -noout -in cert.crt > pubKey.pem
Afterwards, I wanted to print information about key with command below.
openssl rsa -text -pubin -in pubKey.pem
And gets an error: unable to load Public Key
Solution
I opened pubKey.pem in notepad++ and in the Encoding menu was UCS-2 LE BOM selected. So I changed it to UTF-8 encoding. Size of pubKey.pem was half of the original one after changing encoding. Then it works like charm.
Tested in Windows and powershell