Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Encode pre-1.9.3 RSA public keys using X.509 format
require 'openssl'
require 'base64'
rsa =
modulus = rsa.n
exponent = rsa.e
oid ="rsaEncryption")
alg_id =[oid,])
ary = [,]
pub_key =
enc_pk =
subject_pk_info =[alg_id, enc_pk])
base64 = Base64.encode64(subject_pk_info.to_der)
#This is the equivalent to the X.509 encoding used in >= 1.9.3
pem = "-----BEGIN PUBLIC KEY-----\n#{base64}-----END PUBLIC KEY-----"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.