# Blowfish and Rails

**URL:** <https://www.ruby-forum.com/t/blowfish-and-rails/122322>\
**Category:** Ruby\
**Created:** [December 6, 2007, 4:46pm UTC](https://www.ruby-forum.com/t/blowfish-and-rails/122322 "2007-12-06T16:46:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rumz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9de0a6/32.png) [@rumz](https://www.ruby-forum.com/u/rumz)\
**Post date:** [December 6, 2007, 4:46pm UTC](https://www.ruby-forum.com/t/blowfish-and-rails/122322/1 "2007-12-06T16:46:25Z")

</div>

I’m working on encrypting some data using blowfish. My Client uses php  
and blowfish for encryption and i use ror and blowfish  
the php snippet is as follows,

$key = ‘some key’;  
$data = ‘data to be encrypted’

$iv = pack(‘H\*’, substr($key, 0, 16));

$literak\_key =", $key.$key.$key.substr($key,16),";  
$cipher = mcrypt\_module\_open(MCRYPT\_BLOWFISH, ‘’, ‘cbc’, ‘’);  
mcrypt\_generic\_init($cipher, $literalKey, $iv);

When i try to do the same thing using rails, i get a different  
encrypted key.

Also, blow fish can take only 56 byte key as its input, so i  
manipulated the key as how its done in php and packed it to a hex.

however am not sure how i can pass the iv

blowfish = Crypt::Blowfish.new(key)  
encrypted\_string = blowfish.encrypt\_block(plain\_text)

any thoughts? thank you.

Cheers  
Ramya
