Crypt_Blowfish
[ class tree: Crypt_Blowfish ] [ index: Crypt_Blowfish ] [ all elements ]

Class: Crypt_Blowfish

Source Location: /Crypt_Blowfish-1.1.0RC2/Blowfish.php

Class Overview


Example using the factory method in CBC mode


Author(s):

Version:

  • 1.1.0RC2

Copyright:

  • 2005-2008 Matthew Fonda

Variables

Methods


Child classes:

Crypt_Blowfish_MCrypt
Example using the factory method in CBC mode and forcing using the MCrypt library.
Crypt_Blowfish_PHP
Common class for PHP-only implementations

Inherited Variables

Inherited Methods


Class Details

[line 87]
Example using the factory method in CBC mode

  1.  $bf =Crypt_Blowfish::factory('cbc');
  2.  if (PEAR::isError($bf)) {
  3.      echo $bf->getMessage();
  4.      exit;
  5.  }
  6.  $iv 'abc123+=';
  7.  $key 'My secret key';
  8.  $bf->setKey($key$iv);
  9.  $encrypted $bf->encrypt('this is some example plain text');
  10.  $bf->setKey($key$iv);
  11.  $plaintext $bf->decrypt($encrypted);
  12.  if (PEAR::isError($plaintext)) {
  13.      echo $plaintext->getMessage();
  14.      exit;
  15.  }
  16.  // Encrypted text is padded prior to encryption
  17.  // so you may need to trim the decrypted result.
  18.  echo 'plain text: ' trim($plaintext);

To disable using the mcrypt library, define the CRYPT_BLOWFISH_NOMCRYPT constant. This is useful for instance on Windows platform with a buggy mdecrypt_generic() function.

  1.  define('CRYPT_BLOWFISH_NOMCRYPT'true);



[ Top ]


Class Variables

$_block_size =  8

[line 111]

Holds block size
  • Access: protected

Type:   integer


[ Top ]

$_iv =  null

[line 103]

Initialization vector
  • Access: protected

Type:   string


[ Top ]

$_iv_size =  8

[line 119]

Holds IV size
  • Access: protected

Type:   integer


[ Top ]

$_key_size =  56

[line 127]

Holds max key size
  • Access: protected

Type:   integer


[ Top ]



Method Detail

Crypt_Blowfish (Constructor)   [line 139]

Crypt_Blowfish Crypt_Blowfish( string $key)

Crypt_Blowfish Constructor Initializes the Crypt_Blowfish object (in EBC mode), and sets the secret key

Parameters:

string   $key     

[ Top ]

decrypt   [line 294]

string|PEAR_Error decrypt( string $cipherText)

Decrypts an encrypted string

The value was padded with NUL characters when encrypted. You may need to trim the result or cast its type.

  • Return: Returns plain text on success, PEAR_Error on failure
  • Access: public

Overridden in child classes as:

Crypt_Blowfish_MCrypt::decrypt()
Decrypts an encrypted string
Crypt_Blowfish_CBC::decrypt()
Decrypts an encrypted string
Crypt_Blowfish_ECB::decrypt()
Decrypts an encrypted string

Parameters:

string   $cipherText     the binary string to decrypt

[ Top ]

encrypt   [line 278]

string|PEAR_Error encrypt( string $plainText)

Encrypts a string

Value is padded with NUL characters prior to encryption. You may need to trim or cast the type when you decrypt.

  • Return: Returns cipher text on success, PEAR_Error on failure
  • Access: public

Overridden in child classes as:

Crypt_Blowfish_MCrypt::encrypt()
Encrypts a string
Crypt_Blowfish_CBC::encrypt()
Encrypts a string
Crypt_Blowfish_ECB::encrypt()
Encrypts a string

Parameters:

string   $plainText     the string of characters/bytes to encrypt

[ Top ]

factory   [line 165]

object Crypt_Blowfish &factory( [string $mode = 'ecb'], [string $key = null], [string $iv = null], [integer $engine = CRYPT_BLOWFISH_AUTO])

Crypt_Blowfish object factory

This is the recommended method to create a Crypt_Blowfish instance.

When using CRYPT_BLOWFISH_AUTO, you can force the package to ignore the MCrypt extension, by defining CRYPT_BLOWFISH_NOMCRYPT.

  • Return: object or PEAR_Error object on error
  • Since: 1.1.0
  • Access: public

Parameters:

string   $mode     operating mode 'ecb' or 'cbc' (case insensitive)
string   $key     
string   $iv     initialization vector (must be provided for CBC mode)
integer   $engine     one of CRYPT_BLOWFISH_AUTO, CRYPT_BLOWFISH_PHP or CRYPT_BLOWFISH_MCRYPT

[ Top ]

getBlockSize   [line 214]

integer getBlockSize( )

Returns the algorithm's block size
  • Since: 1.1.0
  • Access: public

[ Top ]

getIVSize   [line 226]

integer getIVSize( )

Returns the algorithm's IV size
  • Since: 1.1.0
  • Access: public

[ Top ]

getMaxKeySize   [line 238]

integer getMaxKeySize( )

Returns the algorithm's maximum key size
  • Since: 1.1.0
  • Access: public

[ Top ]

init   [line 263]

bool init( )

Deprecated init method - init is now a private method and has been replaced with _init
  • Deprecated:
  • Access: public

[ Top ]

isReady   [line 250]

bool isReady( )

Deprecated isReady method
  • Deprecated:
  • Access: public

[ Top ]

setKey   [line 311]

boolean|PEAR_Error setKey( string $key)

Sets the secret key The key must be non-zero, and less than or equal to 56 characters (bytes) in length.

If you are making use of the PHP MCrypt extension, you must call this method before each encrypt() and decrypt() call.

  • Return: Returns TRUE on success, PEAR_Error on failure
  • Access: public

Overridden in child classes as:

Crypt_Blowfish_MCrypt::setKey()
Sets the secret key The key must be non-zero, and less than or equal to 56 characters (bytes) in length.
Crypt_Blowfish_PHP::setKey()
Sets the secret key The key must be non-zero, and less than or equal to 56 characters (bytes) in length.

Parameters:

string   $key     

[ Top ]


Documentation generated on Sat, 30 Aug 2008 18:00:05 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.