# Ruby openssl?

**URL:** <https://rubytalk.org/t/ruby-openssl/18996>\
**Category:** ruby-talk\
**Created:** [15 June 2005 23:30 UTC](https://rubytalk.org/t/ruby-openssl/18996 "2005-06-15T23:30:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Kelly](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Bill\_Kelly](https://rubytalk.org/u/Bill_Kelly)\
**Post date:** [15 June 2005 23:30 UTC](https://rubytalk.org/t/ruby-openssl/18996/1 "2005-06-15T23:30:31Z")

</div>

Hi,

I've just begun a project where I'd like to do public  
key encryption, and have been looking for docs and/or  
examples using the ruby openssl library.

So far, I've found:  
[http://www.ruby-doc.org/stdlib/libdoc/openssl/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/openssl/rdoc/index.html)  
and:  
[http://www.nongnu.org/rubypki/README](http://www.nongnu.org/rubypki/README)  
which have been of limited help so far.

So I figured I'd download the source... The RAA page leads  
me to: [http://www.nongnu.org/rubypki/](http://www.nongnu.org/rubypki/) , however the download  
link there is broken.

The CVS browser seems to be working, but there are two  
projects, "ossl", and "ossl2". I'm not sure which is  
the most current / appropriate to checkout. Neither  
seems to have any files recently modified, although the  
README link above warns, "All code is under development -  
API/method names can change."

If anyone can help with either a) finding the correct  
source to download, and/or b) finding some documentation  
and example code, I'd be grateful.. maybe even ebullient.. 🙂

Thanks!

Regards,

Bill

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [15 June 2005 23:50 UTC](https://rubytalk.org/t/ruby-openssl/18996/2 "2005-06-15T23:50:35Z")

</div>

> Hi,
> 
> I've just begun a project where I'd like to do public  
> key encryption, and have been looking for docs and/or  
> examples using the ruby openssl library.

There should be a sample/openssl directory in the ruby tarball.

> So I figured I'd download the source... The RAA page leads  
> me to: [Ruby PKI](http://www.nongnu.org/rubypki/) , however the download  
> link there is broken.

ruby 1.8 includes OpenSSL, so you just need the ruby tarball. The source of openssl itself is probably not worth looking at (but sample/openssl might be).

> **···**
>
> On 15 Jun 2005, at 16:30, Bill Kelly wrote:
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://segment7.net](http://segment7.net)  
> FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

---

<div class="post-metadata">

**Author:** ![Bill\_Kelly](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Bill\_Kelly](https://rubytalk.org/u/Bill_Kelly)\
**Post date:** [16 June 2005 08:15 UTC](https://rubytalk.org/t/ruby-openssl/18996/3 "2005-06-16T08:15:33Z")

</div>

> There should be a sample/openssl directory in the ruby tarball.
> 
> \> So I figured I'd download the source... The RAA page leads  
> \> me to: [Ruby PKI](http://www.nongnu.org/rubypki/) , however the download  
> \> link there is broken.
> 
> ruby 1.8 includes OpenSSL, so you just need the ruby tarball. The  
> source of openssl itself is probably not worth looking at (but sample/  
> openssl might be).

Thanks! .... Hmm..

Anyone know what I'm doing wrong here? I generated a  
public/private key pair, then tried to sign some data  
and verify the signature:

irb(main):001:0\> require 'openssl'  
=\> true  
irb(main):002:0\> include OpenSSL  
=\> Object  
irb(main):003:0\> keypair = PKey::RSA.new(1024)  
=\> -----BEGIN RSA PRIVATE KEY-----  
-----END RSA PRIVATE KEY-----  
irb(main):004:0\> sig = keypair.sign(Digest::MD5.new, "abcdefg")  
=\> "...binary-data..."  
irb(main):005:0\> keypair.verify(Digest::MD5.new, "abcdefg", sig)  
=\> false

...I was hoping the answer would be "true". But I'm  
pretty much guessing as to how to call these methods...

Thanks!

Regards,

Bill

> **···**
>
> From: "Eric Hodel" \<drbrain@segment7.net\>
> 
> > On 15 Jun 2005, at 16:30, Bill Kelly wrote:

---

<div class="post-metadata">

**Author:** ![Pelle\_Braendgaard1](https://avatars.discourse-cdn.com/v4/letter/p/7993a0/32.png) [@Pelle\_Braendgaard1](https://rubytalk.org/u/Pelle_Braendgaard1)\
**Post date:** [16 June 2005 11:22 UTC](https://rubytalk.org/t/ruby-openssl/18996/4 "2005-06-16T11:22:10Z")

</div>

Hi Bill,  
In your verify statement you need to swap the sig and the data

Pelle

> **···**
>
> On 6/16/05, Bill Kelly \<billk@cts.com\> wrote:
> 
> > From: "Eric Hodel" \<drbrain@segment7.net\>  
> > \>  
> > \> On 15 Jun 2005, at 16:30, Bill Kelly wrote:  
> > \>  
> > \> There should be a sample/openssl directory in the ruby tarball.  
> > \>  
> > \> \> So I figured I'd download the source... The RAA page leads  
> > \> \> me to: [Ruby PKI](http://www.nongnu.org/rubypki/) , however the download  
> > \> \> link there is broken.  
> > \>  
> > \> ruby 1.8 includes OpenSSL, so you just need the ruby tarball. The  
> > \> source of openssl itself is probably not worth looking at (but sample/  
> > \> openssl might be).
> > 
> > Thanks! .... Hmm..
> > 
> > Anyone know what I'm doing wrong here? I generated a  
> > public/private key pair, then tried to sign some data  
> > and verify the signature:
> > 
> > irb(main):001:0\> require 'openssl'  
> > =\> true  
> > irb(main):002:0\> include OpenSSL  
> > =\> Object  
> > irb(main):003:0\> keypair = PKey::RSA.new(1024)  
> > =\> -----BEGIN RSA PRIVATE KEY-----  
> > -----END RSA PRIVATE KEY-----  
> > irb(main):004:0\> sig = keypair.sign(Digest::MD5.new, "abcdefg")  
> > =\> "...binary-data..."  
> > irb(main):005:0\> keypair.verify(Digest::MD5.new, "abcdefg", sig)  
> > =\> false
> > 
> > ...I was hoping the answer would be "true". But I'm  
> > pretty much guessing as to how to call these methods...
> > 
> > Thanks!
> > 
> > Regards,
> > 
> > Bill
> 
> --  
> [https://stakeitout.com](https://stakeitout.com) + Stake out your own micro ventures  
> [http://neubia.com](http://neubia.com) + Geek blog  
> [http://stakeventures.com](http://stakeventures.com) + Bootstrapping blog  
> [http://SoapBX.com](http://SoapBX.com) + Get on the box and shout

---

<div class="post-metadata">

**Author:** ![Bill\_Kelly](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Bill\_Kelly](https://rubytalk.org/u/Bill_Kelly)\
**Post date:** [16 June 2005 15:51 UTC](https://rubytalk.org/t/ruby-openssl/18996/5 "2005-06-16T15:51:53Z")

</div>

Hi Pelle,

> \>  
> \> irb(main):004:0\> sig = keypair.sign(Digest::MD5.new, "abcdefg")  
> \> =\> "...binary-data..."  
> \> irb(main):005:0\> keypair.verify(Digest::MD5.new, "abcdefg", sig)
> 
> In your verify statement you need to swap the sig and the data

D'oh !!!! Thanks. I was looking at [http://www.nongnu.org/rubypki/README](http://www.nongnu.org/rubypki/README)  
for reference, which shows, for PKey::RSA,

&nbsp;&nbsp;.sign(oDigest::ANY, sData) =\> sSig  
&nbsp;&nbsp;.verify(oDigest::ANY, sData, sSig) =\> bResult

...guess that document is out of date ☹

Thanks,

Bill

> **···**
>
> > On 6/16/05, Bill Kelly \<billk@cts.com\> wrote:
