[Bcrypt-users] Bcrypt and PHP
Status: Beta
Brought to you by:
jwshelley
From: Brett S. <Bre...@gr...> - 2008-08-08 13:24:56
|
Hello again. I've started looking into a different way to encrypt a file (blowfish) and then send it to a server that uses bcrypt.exe to decrypt it, without requiring bcrypt.exe to do the initial encryption. As the initial data is captured in a PHP script, we're looking at encrypting the data in PHP, sending it to the remote server, where bcrypt.exe is used to decrypt. The following PHP script failed to work. Here is the steps I took. 1. Execute the below PHP script which will create the encrypted file 'test1.txt.bfe' with the contents '1234567890' based on the key 'eggheads'. 2. PHP script creates the blowfish encrypted file 'test1.txt.bfe' 3. Execute 'bcrypt test1.txt.bfe' (to unencrypt the file) 4. Enter the password 'eggheads' into the command line 5. Warning 'Invalid encryption key for file ...' message received <?php $key = 'eggheads'; $filename = 'test1.txt.bfe'; $string = '1234567890'; $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC), MCRYPT_RAND); $encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $string, MCRYPT_MODE_CBC, $iv); $fp = fopen($filename, 'w'); fwrite($fp, $encrypted_string); fclose($fp); // 1. To test decryption of file with bcrypt, execute 'bcrypt test1.txt.bfe' // 2. Prompted for password, enter 'eggheads' // 3. File 'test1.txt' will appear in file system ?> QUESTION. You may not have knowledge with PHP but is there something obvious I'm missing here? Is it something to do with the IV or MODE (CBC/ECB)? Thank you :) Brett. |