If it's an RSA key you can construct it from its parameters.
require 'openssl'
module OpenSSL
module PKey
class RSA
# Construct an RSA key from parameters.
# Input: a large number n
# an exponent
# For private keys you also need:
# factor p of n
# factor q of n (n = p * q)
# if d is nil then it is calculated from p and q
def self.new_from_parameters(n, e, d=nil, p=nil, q=nil)
a = self.new # self.new(64) for ruby < 1.8.2
a.n = n # converted to OpenSSL::BN automatically
a.e = e
if p and q
p,q = q,p if p < q
a.p = p
a.q = q
raise "n != p * q" unless a.n == a.p * a.q
a.d = d || a.e.mod_inverse((a.p-1)*(a.q-1))
a.dmp1 = a.d % (a.p-1)
a.dmq1 = a.d % (a.q-1)
a.iqmp = a.q.mod_inverse(a.p)
else
a.d = d
a.p = nil
a.q = nil
end
a
end
end
end
end
Then to convert it into a PEM format, all you need is:
puts OpenSSL::PKey::RSA.new_from_parameters(n, e)
The key you give is 1160 bits in total, maybe 1024 bits of product and
136 bits of exponent? You'll need to find out its structure.
--
Posted via http://www.ruby-forum.com/.