# 2 Way encryption for password

**URL:** <https://www.ruby-forum.com/t/2-way-encryption-for-password/113588>\
**Category:** Ruby\
**Created:** [September 2, 2007, 12:34pm UTC](https://www.ruby-forum.com/t/2-way-encryption-for-password/113588 "2007-09-02T12:34:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [September 2, 2007, 12:34pm UTC](https://www.ruby-forum.com/t/2-way-encryption-for-password/113588/1 "2007-09-02T12:34:48Z")

</div>

Hi

I’m creating a password database (a dangerous thing to do, I know!)  
normally I’d hash the passwords for storage in the DB, but in this  
case I need to be able to also reverse them to their original state.  
I’m familiar with the digest module, but of course it isn’t of use  
here. I didn’t see anything obvious on my Google travels. Could  
anyone suggest how to perform encryption in ruby, in particular based  
on a rails application…?

Many thanks

Gabriel

---

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [September 2, 2007, 1:48pm UTC](https://www.ruby-forum.com/t/2-way-encryption-for-password/113588/2 "2007-09-02T13:48:53Z")

</div>

Gabriel D. wrote:

> Many thanks
> 
> Gabriel

Have a look here:  
[Crypto in ruby - Stake Ventures](http://stakeventures.com/articles/2005/06/16/crypto-in-ruby) (OpenSSL  
contains many encryption algorithms), and you might want to browse this  
list:  
[http://raa.ruby-lang.org/cat.rhtml?category\_major=Library;category\_minor=Cryptography](http://raa.ruby-lang.org/cat.rhtml?category_major=Library;category_minor=Cryptography)

Hope this helps,  
Dan

---

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [September 3, 2007, 12:20am UTC](https://www.ruby-forum.com/t/2-way-encryption-for-password/113588/3 "2007-09-03T00:20:00Z")

</div>

On Sun, Sep 02, 2007 at 07:33:51PM +0900, Gabriel D. wrote:

> Hi
> 
> I’m creating a password database (a dangerous thing to do, I know!)  
> normally I’d hash the passwords for storage in the DB, but in this  
> case I need to be able to also reverse them to their original state.  
> I’m familiar with the digest module, but of course it isn’t of use  
> here. I didn’t see anything obvious on my Google travels. Could  
> anyone suggest how to perform encryption in ruby, in particular based  
> on a rails application…?

You might want to check out keybox and see if it would meet your needs.

```
http://keybox.rubyforge.org/

```

Its a pure ruby password database utilizing the SSL libraries for  
encryption. It ships as a commandline application but it is fully  
utilizable via its API.

If you have any questions, feel free to let me know.

enjoy,

-jeremy

---

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [September 2, 2007, 6:39pm UTC](https://www.ruby-forum.com/t/2-way-encryption-for-password/113588/4 "2007-09-02T18:39:35Z")

</div>

On 2 Sep 2007, at 12:47, Dan Z. wrote:

> > Gabriel
> 
> Have a look here: [http://stakeventures.com/articles/2005/06/16/](http://stakeventures.com/articles/2005/06/16/)  
> crypto-in-ruby (OpenSSL contains many encryption algorithms), and  
> you might want to browse this list: [http://raa.ruby-lang.org/](http://raa.ruby-lang.org/)  
> cat.rhtml?category\_major=Library;category\_minor=Cryptography
> 
> Hope this helps,  
> Dan

Thank you very much, never thought of using the SSL library!

Regards

Gabe

---

<div class="post-metadata">

**Author:** ![mobileamusement](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mobileamusement](https://www.ruby-forum.com/u/mobileamusement)\
**Post date:** [September 3, 2007, 7:33am UTC](https://www.ruby-forum.com/t/2-way-encryption-for-password/113588/5 "2007-09-03T07:33:24Z")

</div>

Gabriel D. wrote:

> Hi
> 
> I’m creating a password database (a dangerous thing to do, I know!)  
> normally I’d hash the passwords for storage in the DB, but in this  
> case I need to be able to also reverse them to their original state.  
> I’m familiar with the digest module, but of course it isn’t of use  
> here. I didn’t see anything obvious on my Google travels. Could  
> anyone suggest how to perform encryption in ruby, in particular based  
> on a rails application…?
> 
> Many thanks
> 
> Gabriel

Small nitpick about terminology: encryption is per definition 2 way,  
what is often wrongly refered to as 1 way encryption is normally  
cryptographic hashing (also see the note  
[http://en.wikipedia.org/wiki/One-way\_encryption:](http://en.wikipedia.org/wiki/One-way_encryption:) “Note that encryption  
is, by definition, reversible. Hence, the term one-way encryption is  
slightly incorrect in a sense.”)

Regards  
Stefan
