# New AES gem available -- fast-aes

**URL:** <https://www.ruby-forum.com/t/new-aes-gem-available-fast-aes/181926>\
**Category:** Ruby\
**Created:** [January 20, 2010, 9:50am UTC](https://www.ruby-forum.com/t/new-aes-gem-available-fast-aes/181926 "2010-01-20T09:50:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nwiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nwiger](https://www.ruby-forum.com/u/nwiger)\
**Post date:** [January 20, 2010, 9:50am UTC](https://www.ruby-forum.com/t/new-aes-gem-available-fast-aes/181926/1 "2010-01-20T09:50:31Z")

</div>

I’ve just released a new AES gem for Ruby, written in C for speed.  
This gem leverages some open source AES C code that has been in use  
for many years. I created this gem because other AES implementations  
didn’t even run, or were buggy, or performed poorly, or all of the  
above.

To install:

gem install fast-aes

Usage is very easy and docs are available here:

[GitHub - nateware/fast-aes: Simple but LOW security AES EBC implementation for Ruby](http://github.com/nateware/fast-aes)

Enjoy,

Nate W.

---

<div class="post-metadata">

**Author:** ![nwiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nwiger](https://www.ruby-forum.com/u/nwiger)\
**Post date:** [July 1, 2010, 4:47pm UTC](https://www.ruby-forum.com/t/new-aes-gem-available-fast-aes/181926/2 "2010-07-01T16:47:41Z")

</div>

Nate W. wrote:

> I’ve just released a new AES gem for Ruby, written in C for speed.  
> This gem leverages some open source AES C code that has been in use

Great. Hopefully what I’ve been looking for.

I’ve been using Encryptor.encrypt(:value =\> string , :key =\> key,  
:algorithm =\> ‘aes-128-cbc’) in a module created on my own. Is your gem  
faster?

I should add that I don’t fully understand this thing with encryption  
and the terminology. Could you explain a bit the key length and 128 bit?  
Is it always the length as in your example?

---

<div class="post-metadata">

**Author:** ![nwiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nwiger](https://www.ruby-forum.com/u/nwiger)\
**Post date:** [July 1, 2010, 5:45pm UTC](https://www.ruby-forum.com/t/new-aes-gem-available-fast-aes/181926/3 "2010-07-01T17:45:29Z")

</div>

2010/7/1 PÃ¥l BergstrÃ¶m [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> I should add that I don’t fully understand this thing with encryption  
> and the terminology. Could you explain a bit the key length and 128 bit?  
> Is it always the length as in your example?

Empirically yes:

require ‘rubygems’  
require ‘fast-aes’  
require ‘pp’

key , results = String.new , Array.new

for char in [_‘a’…‘z’] + [_‘A’…‘H’]  
results \<\< begin  
FastAES.new key and “Valid: #{key}”  
rescue =\> error  
error  
end  
key \<\< char  
end

pp results

Definitively (fast\_aes.c), still yes:

key\_bits = strlen(key\_data)\*8;  
switch(key\_bits)  
{  
case 128:  
case 192:  
case 256:  
fast\_aes-\>key\_bits = key\_bits;  
memcpy(fast\_aes-\>key, key\_data, key\_bits/8);  
/_printf(“AES key=%s, bits=%d\n”, fast\_aes-\>key,  
fast\_aes-\>key\_bits);_/  
break;  
default:  
sprintf(error\_mesg, “AES key must be 128, 192, or 256 bits in  
length  
(got %d): %s”, key\_bits, key\_data);  
rb\_raise(rb\_eArgError, error\_mesg);  
return Qnil;  
}

---

<div class="post-metadata">

**Author:** ![nwiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nwiger](https://www.ruby-forum.com/u/nwiger)\
**Post date:** [July 1, 2010, 6:12pm UTC](https://www.ruby-forum.com/t/new-aes-gem-available-fast-aes/181926/4 "2010-07-01T18:12:41Z")

</div>

Josh C. wrote:

> Definitively (fast\_aes.c), still yes:

And for saving it in mysql, how do I translate it from binary (?)  
“garbage” characters (is that how you explain it) to a string? I use  
Base64.b64encode(fast\_aes\_string) now. Is there a faster way?
