[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

OpenSSL with Ruby

Vaibhav Bhandari

4/16/2008 10:17:00 PM

hi all -

I'm not sure if this is the correct forum but i was wondering if
anyone has successfully done RSA-SHA1 signing with Ruby OpenSSL and
interoperated with Java Servers.

I'm using the following code but i'm not sure if the "sign" method on
works properly -

@key = OpenSSL::PKey::RSA.new(2048)
#sign
@key.send("sign", OpenSSL::Digest.::SHA1.new, "text to sign")

The expected signature from above "sign" is not what i know the Java
crytpo api likes.

Thanks in advance.

regards,
Vaibhav

4 Answers

Rolando Abarca

4/16/2008 10:34:00 PM

0

On Apr 16, 2008, at 6:16 PM, vaibhavb wrote:

> hi all -
>
> I'm not sure if this is the correct forum but i was wondering if
> anyone has successfully done RSA-SHA1 signing with Ruby OpenSSL and
> interoperated with Java Servers.
>
> I'm using the following code but i'm not sure if the "sign" method on
> works properly -
>
> @key = OpenSSL::PKey::RSA.new(2048)
> #sign
> @key.send("sign", OpenSSL::Digest.::SHA1.new, "text to sign")
>
> The expected signature from above "sign" is not what i know the Java
> crytpo api likes.
>
> Thanks in advance.

after digging forums and searching through the source, this is what
i'm doing to sign:

digest = OpenSSL::Digest::SHA1.new(text_to_sign)
sign = key.private_encrypt(digest)
# sign is what you want, if you need it in Base64:
enc_sign = Base64.encode64(sign)

> regards,
> Vaibhav

regards,
--
Rolando Abarca M.





Matt Todd

4/16/2008 10:41:00 PM

0

> enc_sign = Base64.encode64(sign)

Bawse64.encode64 is deprecated. Check out String#pack instead
(specifically the "m*" option).

Vaibhav Bhandari

4/16/2008 10:50:00 PM

0

I tried the above but it still is not same as Java output - I want to
be able to sign and update each byte of the text instead of string
(thats what Java does) .. any ideas?

Thanks in advance.

regards,
Vaibhav

On Apr 16, 3:33 pm, Rolando Abarca <funkas...@gmail.com> wrote:
> On Apr 16, 2008, at 6:16 PM, vaibhavb wrote:
>
>
>
> > hi all -
>
> > I'm not sure if this is the correct forum but i was wondering if
> > anyone has successfully done RSA-SHA1 signing with Ruby OpenSSL and
> > interoperated with Java Servers.
>
> > I'm using the following code but i'm not sure if the "sign" method on
> > works properly -
>
> > @key = OpenSSL::PKey::RSA.new(2048)
> > #sign
> > @key.send("sign", OpenSSL::Digest.::SHA1.new, "text to sign")
>
> > The expected signature from above "sign" is not what i know the Java
> > crytpo api likes.
>
> > Thanks in advance.
>
> after digging forums and searching through the source, this is what
> i'm doing to sign:
>
> digest = OpenSSL::Digest::SHA1.new(text_to_sign)
> sign = key.private_encrypt(digest)
> # sign is what you want, if you need it in Base64:
> enc_sign = Base64.encode64(sign)
>
> > regards,
> > Vaibhav
>
> regards,
> --
> Rolando Abarca M.

Eric I.

4/26/2008 10:30:00 PM

0

Hi Vaibhav,

Any chance you're dealing with a character encoding issue? By default
Java uses UTF-16. And you may be using UTF-8 with Ruby. Just a
thought....

Eric
----
Are you interested in on-site Ruby and/or Ruby on Rails training that
uses
well-designed, real-world, hands-on exercises? http://Lea...


On Apr 16, 6:50 pm, vaibhavb <vaibh...@gmail.com> wrote:
> I tried the above but it still is not same as Java output - I want to
> be able to sign and update each byte of the text instead of string
> (thats what Java does) .. any ideas?
>
> Thanks in advance.
>
> regards,
> Vaibhav
>