# Openssl for general purpose data encryption in Ruby

**URL:** <https://www.ruby-forum.com/t/openssl-for-general-purpose-data-encryption-in-ruby/74887>\
**Category:** Ruby\
**Created:** [November 7, 2006, 10:59am UTC](https://www.ruby-forum.com/t/openssl-for-general-purpose-data-encryption-in-ruby/74887 "2006-11-07T10:59:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brad7a0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/53a042/32.png) [@brad7a0](https://www.ruby-forum.com/u/brad7a0)\
**Post date:** [November 7, 2006, 10:59am UTC](https://www.ruby-forum.com/t/openssl-for-general-purpose-data-encryption-in-ruby/74887/1 "2006-11-07T10:59:55Z")

</div>

Does anyone use openssl within Ruby to encrypt data? I want to use a  
hosted  
MySQL database, but most of the hosting companies do not support MySQL  
with the  
aes\_encrypt() or aes\_decrypt() functions.

Most have Ruby bindings to MySQL and they support Rails. So, I thought I  
could  
use openssl to encrypt data within Ruby and then store that data in the  
database. I don’t know if others are doing this. I thought I’d ask the  
list to  
see if others do this.

Thank you,  
Brad

---

<div class="post-metadata">

**Author:** ![brad7a0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/53a042/32.png) [@brad7a0](https://www.ruby-forum.com/u/brad7a0)\
**Post date:** [November 7, 2006, 11:01am UTC](https://www.ruby-forum.com/t/openssl-for-general-purpose-data-encryption-in-ruby/74887/2 "2006-11-07T11:01:18Z")

</div>

On 11/4/06, Brad T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Brad  
> I’m not doing it ('cause I just don’t need it ;-). Anyway I think it  
> should work. However please note some possible problems:

1. you’ll want o have your records independent - therefore either  
using ECB mode or special IV for each record.

2. you don’t want to have the same data in different places encrypted  
into the same ciphertexts - therefore you’ll need either IV or some  
kind of salt, that you’ll need to store somewhere (it depends on the  
data you store, maybe a per row IV would be enough)

3. most probably you can’t encrypt the index fields, and search will  
not work as usual on encrypted fields.

Taking this into consideration, it should be possible to create a  
schema that will work.

(If you don’t know what these IV, ECB and salt things are, I recommend  
reading something on cryptography, e.g. [1]. It’s easy to get crypto  
wrong, and useless)

[1] [Centre For Applied Cryptographic Research: The University of Waterloo](http://www.cacr.math.uwaterloo.ca/hac/)
