Public Key encryption

M

MrBanabas

Hi all,

I have to talk to a third party system in one of my applications.

The login message has to be encrypted with their public key.
However, in their documentation they only present me the key and not a
pem file:
Does anybody know how I may configure OPENSSL if I only have the
public key ?

Key from their documentation:
480152500100000081009CA3D65EAC3318178F31667C3C5E60EE26DD6B090B2671928F8D461B598731AE931A2C8D02B593189DCDF17C591634DE10657AA9957CB6D9952B9040C96536F96A4BFDF0F97703893EF8D52AA91762B85D010AFCE4C3E6CB0338559DECA54D774A6640CB57B8F169B96ED223000FC950254646FA8AD7AA4361D1BCAE9694477D00000003010001


Thanks a lot in advance.
 
M

Marnen Laibow-Koser

Hi all,

I have to talk to a third party system in one of my applications.

The login message has to be encrypted with their public key.
However, in their documentation they only present me the key and not a
pem file:
Does anybody know how I may configure OPENSSL if I only have the
public key ?

Key from their documentation:
480152500100000081009CA3D65EAC3318178F31667C3C5E60EE26DD6B090B2671928F8D461B598731AE931A2C8D02B593189DCDF17C591634DE10657AA9957CB6D9952B9040C96536F96A4BFDF0F97703893EF8D52AA91762B85D010AFCE4C3E6CB0338559DECA54D774A6640CB57B8F169B96ED223000FC950254646FA8AD7AA4361D1BCAE9694477D00000003010001


Thanks a lot in advance.

What does this have to do with Ruby?

Best,
 
M

MrBanabas

Hi,

Well, I have nt thought about the fact that there might be a special
group for ruby openssl lib. Sorry for that.

Just to explain my decision to post this to a ruby group...
If I would have a pem file I would do the following in ruby:
public_key = OpenSSL::pKey::RSA.new(File.new(pem_file))
encrypted_string = Base64.encode64(public_key.public_encrypt(string))

Maybe somebody can point me to a more appropriate group ?

Thanks a lot in advance.
 
B

Brian Candler

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top