"bf-cbc" Cipher with Salted Key

A tutorial example is provided to show you how to use the 'bf-cbc' cipher with Salted Key to encrypt and decrypt binary data files. The Secret Key and the IV will be derived from the given passphrase and the given salt.

Similar to the OpenSSL "enc -bf-ecb" command, we can also run the "enc -bf-cbc" command in the "Salted Key" way by using "-pass" and "-S" options:

Here is my first test using OpenSSL "enc -bf-cbc" command in the "Salted Key" way with "-pass pass:" and "-S" options.

C:\herong> \
   perl -e "binmode(STDOUT); print pack('H*', '0000000000000000')" \
   > 2-block.txt

C:\herong> \
   perl -e "binmode(STDOUT); print pack('H*', '0000000000000000')" \
   >> 2-block.txt

C:\herong>\local\gnuwin32\bin\openssl enc -bf-cbc -e \
   -pass pass:MySecret -S 0000000000000000 \
   -in 2-block.txt -out cipher.txt -nopad -p
   
salt=0000000000000000
key=0B90D83D1A281A744F4F340911D8E0A6
iv =6FF60FCD91D7F34E

C:\herong>perl -e "print unpack('H*',v>)" < cipher.txt

53616c7465645f5f 0000000000000000 606a204b0f2aab9c7762557547f3ea05
---------------- ---------------- --------------------------------
   "Salted__"          Salt           Cipher blocks


C:\herong>\local\gnuwin32\bin\openssl enc -bf-cbc -d \
   -pass pass:MySecret -in cipher.txt -out decrypted.txt -nopad -p
   
salt=0000000000000000
key=0B90D83D1A281A744F4F340911D8E0A6
iv =6FF60FCD91D7F34E

C:\herong>perl -e "while (read(STDIN,$_,1)){print unpack('H*',$_);}" \
   < decrypted.txt
   
00000000000000000000000000000000

The output confirms that:

Last update: 2018.

Table of Contents

 About This Book

 Blowfish Cipher Algorithm

 Perl Crypt::Blowfish Module

 Perl Crypt::ECB Perl Module

 Perl Crypt::CBC Module

 Perl Crypt::CFB Perl Module

 OpenSSL "enc -bf-ecb" for Blowfish/ECB Encryption

OpenSSL "enc -bf-cbc" for Blowfish/CBC Encryption

 "bf-cbc" Cipher with Literal Key

 "bf-cbc" Cipher on Multiple Blocks

 "bf-cbc" Encryption Verification

 "bf-cbc" 2-Block Test Vectors

"bf-cbc" Cipher with Salted Key

 "bf-cbc" Cipher with Random Salt

 "enc -bf-cbc" Command Summary

 OpenSSL "enc -bf-cfb" for Blowfish/CFB Encryption

 OpenSSL "enc -bf-ofb" for Blowfish/OFB Encryption

 PHP Mcrypt Extension for Blowfish

 Blowfish 8-Bit Cipher in PHP

 References

 Full Version in PDF/EPUB