Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.