I have .p12 file from Apple and tried to convert it to .pem file with following command:
openssl pkcs12 -in cert.p12 -out apple_push_notification_development
I've had the same problem and im my case I needed to decode file content with Base64.
require 'openssl'
require 'base64'
encoded_content = File.read('apple_push_notification_development.pem')
decoded_content = Base64.decode64(encoded_content)
certificate = OpenSSL::X509::Certificate.new(decoded_content)