What is Crypt::ECB

A quick introduction is provided for the Crypt::ECB Perl module, which can be used to perform encryption and decryption in the ECB (Electronic CodeBook) operation mode with a given block cipher for any number of blocks.

What Is Crypt::ECB? Crypt::ECB is a Perl module providing ECB (Electronic CodeBook) block cipher operation mode functionality. Crypt::ECB was developed by Christoph Appel.

Here is the description of Crypt::ECB on the cpan.org Web site: "This module is a Perl-only implementation of the ECB mode. In combination with a block cipher such as DES, IDEA or Blowfish, you can encrypt and decrypt messages of arbitrarily long length. Though for security reasons other modes than ECB such as ECB should be preferred. See textbooks on cryptography if you want to know why."

In case you forgot how ECB (Electronic CodeBook) works, here a shortest version of the ECB algorithm:

 
Input:
   P: The plaintext in multiple blocks
   K: The secret key
   E(K,B): The block encryption function 

Output:
   C: The ciphertext in multiple blocks

Algorithm - ECB (Electronic CodeBook) Operation Mode: 
   (P[1], P[2], P[3},...) = P    : Split plaintext into blocks

   Loop i over 1,2,3,...
      C[i] = E(K, P[i])
   End Loop
   
   C = (C[1], C[2], C[3},...)    : Concatenate ciphertext blocks

The ECB algorithm can also be illustrated by this simple diagram:

Algorithm - ECB (Electronic CodeBook) Operation Mode: 

   P[1]   P[2]   P[3] ...
     |      |      |
   E(K)   E(K)   E(K)
     |      |      | 
   C[1]   C[2]   C[3]

Crypt::ECB module offers the following major methods to perform the ECB operation algorithm described above. Other methods will be discussed later as needed.

$c = Crypt::ECB->new($key, $algorithm) - Returns a new Crypt::ECB cipher operation object with a given secret key and given cipher algorithm. To use Crypt::ECB with Crypt::Blowfish, you need to specify $algorithm = 'Blowfish'. The secret key must be between 8 bytes and 56 bytes long, when Crypt::Blowfish is used.

$c->padding(PADDING_NONE|PADDING_AUTO) - Turns off or on the padding option. Default is off.

$c->start('encrypting|decrypting') - Initialize the cipher operation object $c to start a new encryption or decryption operation.

$c->crypt($text) - Returns the next output block from the current encryption or decryption operation with the given extra input. This method is designed to be used in a loop to encrypt or decrypt large input in chunks.

$c->finish() - Returns the last output block from the current encryption or decryption operation.

$c->encrypt($plaintext) - Returns the ciphertext as the encryption output from the specified plaintext.

$c->decrypt($ciphertext) - Returns the plaintext as the decryption output from the specified ciphertext.

See "Crypt::ECB" Web page at http://search.cpan.org/~appel/Crypt-ECB-1.45/ECB.pm for more information.

Table of Contents

 About This Book

 Blowfish Cipher Algorithm

 Perl Crypt::Blowfish Module

Perl Crypt::ECB Perl Module

What is Crypt::ECB

 Installing Crypt::ECB 1.45 with ActivePerl

 Crypt::ECB Encryption with No Padding

 Crypt::ECB Encryption Test Cases

 Crypt::ECB Auto Padding

 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

 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