Public Key encryption

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.

···

--
volker

MrBanabas@googlemail.com wrote:

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,

···

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

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.

···

--
Volker

On 15 Jan., 03:12, Marnen Laibow-Koser <mar...@marnen.org> wrote:

MrBana...@googlemail.com wrote:
> 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,
--
Marnen Laibow-Koserhttp://www.marnen.org
mar...@marnen.org
--
Posted viahttp://www.ruby-forum.com/.

Hi,

forget about my question. Seems to be a totally proprietary system.

···

--
Volker

On 15 Jan., 09:15, "MrBana...@googlemail.com" <mrbana...@googlemail.com> wrote:

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.

--
Volker

On 15 Jan., 03:12, Marnen Laibow-Koser <mar...@marnen.org> wrote:

> MrBana...@googlemail.com wrote:
> > 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,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> mar...@marnen.org
> --
> Posted viahttp://www.ruby-forum.com/.

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/.