Blowfish Encryption

From: Date: Tue, 08 Jun 2010 03:20:59 +0000
Subject: Blowfish Encryption
Groups: php.general 
Request: Send a blank email to php-general+get-305941@lists.php.net to get a copy of this message
I've got a file of passwords I'd like to encrypt/decrypt using blowfish. I'd like to be able to do so with PHP and via the command line. I have a Linux utility call "bcrypt" which encrypts/decrypts files using blowfish. And I'm using the following code under PHP to do encryption/decryption: $raw_data = file('junk'); $input = implode('', $raw_data); $td = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_ECB, ''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $key, $iv); $encrypted_data = mcrypt_generic($td, $input); file_put_contents('encjunk', $encrypted_data); mcrypt_generic_deinit($td); mcrypt_module_close($td); Now, here's the problem. I'm using bcrypt to encrypt my junk file and dump it out to an encrypted file. And I'm using the above PHP code to encrypt the same file out to a different file. Using the same keys in both cases, I get different encrypted files. My logic: using the same encryption method and the same key, two different implementations should produce equivalent files. Yet they don't. I'm guessing that the "initialization vector" is different between the two implementations, resulting in the difference between the encrypted files. For those who know more about encryption than I do, does that sound right? Paul -- Paul M. Foster

« previous php.general (#305941) next »