# Encrypting data using Blowfish/cbc

**URL:** <https://www.ruby-forum.com/t/encrypting-data-using-blowfish-cbc/90927>\
**Category:** Rails\
**Created:** [April 3, 2007, 2:05am UTC](https://www.ruby-forum.com/t/encrypting-data-using-blowfish-cbc/90927 "2007-04-03T02:05:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jseidel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@jseidel](https://www.ruby-forum.com/u/jseidel)\
**Post date:** [April 3, 2007, 2:05am UTC](https://www.ruby-forum.com/t/encrypting-data-using-blowfish-cbc/90927/1 "2007-04-03T02:05:02Z")

</div>

I need to encrypt/decrypt some data in my application. I downloaded  
crypt-1.1.4.zip and installed it successfully. But when I run a simple  
test program, I get the following error:

`
C:/Dev/InstantRails/ruby/lib/ruby/site_ruby/1.8/crypt/cbc.rb:31:in
`encrypt_stream': undefined method `write' for "":String
(NoMethodError)
        from testcrypt.rb:8
`

Program is very simple:

`
require 'crypt/blowfish'
tkey = '12345'
tblow = Crypt::Blowfish.new(tkey)
testblock = 'abcdeft12345'
testcrypt = ''
tblow.encrypt_stream(testblock,testcrypt)
tblow.decrypt_stream(testcrypt,testdecrypt)
puts testblock, testdecrypt
`

Crypt::Blowfihs mixes in Crypt::CBC which requires ‘stringio’, which  
is where I’m guessing the write method should be.

Any pointers as to what I’m doing wrong here?

Thanks much…jon

---

<div class="post-metadata">

**Author:** ![jseidel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@jseidel](https://www.ruby-forum.com/u/jseidel)\
**Post date:** [May 6, 2007, 2:18am UTC](https://www.ruby-forum.com/t/encrypting-data-using-blowfish-cbc/90927/2 "2007-05-06T02:18:47Z")

</div>

That means it’s expecting ‘stream’ access, while you’re passing it a  
string – I ran into the same problem, researched it, and finally gave  
up.

Now I use Pelle Braendgaard’s EzCrypto module:  
gem install ezcrypto

HTH…jon
