OpenSSL with Ruby

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

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

#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,

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

enc_sign = Base64.encode64(sign)

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

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://LearnRuby.com