<?php
/*
############################[ <about> ] #######################
Author :: Bijaya Kumar Behera <hide@address.com>
Website :: http://digitalwebsolutions.in
Add :: +91 9911033016 ,011-25331969
############################[ </about> ] #######################
*/
class mcryptCryptography {
private $hiddenKey, $iv_size , $td ;
function __construct($hiddenKey) {
$this->hiddenKey =md5($hiddenKey);
$this->td = mcrypt_module_open('des', '','cfb', '');
$this->hiddenKey = substr($this->hiddenKey, 0, mcrypt_enc_get_key_size($this->td));
$this->iv_size = mcrypt_enc_get_iv_size($this->td);
}
function encrypt($input) {
$iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
if (mcrypt_generic_init($this->td, $this->hiddenKey, $iv) != -1) {
$c_t = mcrypt_generic($this->td, $input);
$c_t = $iv.$c_t;
return base64_encode( $c_t) ;
}
return null;
}
function decrypt($encrypted) {
$encrypted = base64_decode($encrypted) ;
$iv = substr($encrypted,0,$this->iv_size);
$encrypted = substr($encrypted,$this->iv_size);
if (mcrypt_generic_init($this->td, $this->hiddenKey, $iv) != -1) {
$c_t = mdecrypt_generic($this->td, $encrypted);
return $c_t;
}
return null;
}
public static function &getInstance() {
static $objCipher = array() ;
if( !$objCipher ) {
$objCipher[0]= & new mcryptCryptography( defined(SECURITY_SALT) ? SECURITY_SALT : $_SERVER['SERVER_NAME'] );
}
return $objCipher[0];
}
public function __destruct() {
$o =mcryptCryptography::getInstance() ;
mcrypt_generic_deinit($this->td);
mcrypt_module_close($this->td);
unset($o );
}
}
?>