Source for file Encryption.class.php
Documentation is available at Encryption.class.php
* Gumbo Library Framework
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* Abstract Encryption Class
* This class provides the foundation for creating encryption/decryption
* algorithms. The Encryption system is based on two complimentary classes.
* The first will Encrypt, the second Decrypt. Each class will define it's
* algorithm inside the 'parse' method.
* The encoding option is responsible for formatting the data into a safe
* format, usually for saving inside a database. Typically, with the mcrypt
* library, the encrypted characters are not safe to input into a database.
* The Encode option replaces the characters with database safe ones, but does
* not lose any information.
* Raw data indicates data that is not encrypted. An Encrypt class receives
* 'raw' data, a Decrypt class will generate 'raw' data. The 'parse' method
* should define the state of the data after completion.
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* @desc Abstract Encryption Class
/** @var string $_data text to be encrypted/decrypted */
/** @var string $_cipher MCRYPT_* cipher */
private $_cipher =
GUMBO_ENCRYPT_CIPHER;
/** @var string $_mode MCRYPT_MODE_* mode */
private $_mode =
GUMBO_ENCRYPT_MODE;
/** @var string $_key encryption/decryption key */
private $_key =
GUMBO_ENCRYPT_KEY;
/** @var bool $_encode if the data is to be encoded or decoded */
private $_encode =
GUMBO_ENCRYPT_ENCODE;
/** @var bool $_raw if the data is raw or encrypted/decrypted */
* Parses the data into an encrypted/decrypted format
* @postcondition isRaw() => [true|false]
abstract public function parse ();
* Sets if the data is Raw, or encrypted/decrypted
* Raw data is the initial data sent into an Encryption class. If using
* Encryption, this will be the data viewable to the user. If using
* Decryption, this would be the encrypted string.
* @throws Gumbo_Exception
protected function setRaw ($val) {
$e->setFunction (__METHOD__
);
* Sets the data to be encrypted/decrypted
* @postcondition setRaw(true)
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* @throws Gumbo_Exception
public function setKey ($key) {
$e->setFunction (__METHOD__
);
* @precondition must be a MCRYPT_* constant
* @throws Gumbo_Exception
case MCRYPT_3DES :
break;
case MCRYPT_BLOWFISH :
break;
case MCRYPT_CAST_128 :
break;
case MCRYPT_CAST_256 :
break;
case MCRYPT_CRYPT :
break;
case MCRYPT_GOST :
break;
case MCRYPT_SAFER64 :
break;
case MCRYPT_SAFER128 :
break;
case MCRYPT_THREEWAY :
break;
case MCRYPT_IDEA :
break;
case MCRYPT_ARCFOUR_IV :
break;
case MCRYPT_ARCFOUR :
break;
// case MCRYPT_ENIGMA : break;
case MCRYPT_LOKI97 :
break;
case MCRYPT_MARS :
break;
case MCRYPT_PANAMA :
break;
case MCRYPT_RIJNDAEL_128 :
break;
case MCRYPT_RIJNDAEL_192 :
break;
case MCRYPT_RIJNDAEL_256 :
break;
case MCRYPT_SAFERPLUS :
break;
case MCRYPT_SERPENT :
break;
case MCRYPT_SKIPJACK :
break;
case MCRYPT_WAKE :
break;
case MCRYPT_XTEA :
break;
// case MCRYPT_DES_COMPAT : break;
// case MCRYPT_RC4 : break;
// case MCRYPT_RC6_128 : break;
// case MCRYPT_RC6_192 : break;
// case MCRYPT_RC6_256 : break;
// case MCRYPT_SERPENT_128 : break;
// case MCRYPT_SERPENT_192 : break;
// case MCRYPT_SERPENT_256 : break;
// case MCRYPT_TEAN : break;
default : throw
new Gumbo_Exception ("Encryption Cipher Does Not Exist: {$cipher}");
$e->setFunction (__METHOD__
);
* Sets the mode of encryption
* @precondition must be a MCRYPT_MODE_* constant
* @throws Gumbo_Exception
case MCRYPT_MODE_ECB :
break;
case MCRYPT_MODE_CBC :
break;
case MCRYPT_MODE_CFB :
break;
case MCRYPT_MODE_OFB :
break;
case MCRYPT_MODE_NOFB :
break;
case MCRYPT_MODE_STREAM :
break;
default : throw
new Gumbo_Exception ("Encryption Mode Does Not Exist: {$mode}");
$e->setFunction (__METHOD__
);
* Sets if the text should be encoded
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* Returns if the data is raw
public function isRaw () {
* Returns the encrypted/decrypted data
* Returns the encryption mode
* Returns if the text should be encoded