note 112147 deleted from classobj.examples by googleguy
| From: | googleguy@php.net | Date: | Fri, 10 May 2013 11:05:56 +0000 |
| Subject: | note 112147 deleted from classobj.examples by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194767@lists.php.net to get a copy of this message | ||
Note Submitter: hafiz at bhuiyansoft dot com
----
<?php
/**
* Description of cryptography class for data encrypt and decrypt
* @author BhuiyanSoft
*/
interface intf_crypt
{
public function __construct();
public function setCipherModule($cip,$mod);
public function encrypt($str,$key);
public function decrypt($str,$key);
public function encode($input);
public function decode($input);
public function hash($algo,$data);
}
class bscrypt implements intf_crypt
{
public $init_vector;
public $cip_block_size;
public $cipher;
public $module;
public $mode_enc;
public $mode_dec;
public $str;
public function __construct()
{
$this->cipher= MCRYPT_CAST_256;
$this->module= MCRYPT_MODE_CBC;
$this->mode_enc= MCRYPT_ENCRYPT;
$this->mode_dec= MCRYPT_DECRYPT;
$this->cip_block_size= mcrypt_get_block_size ($this->cipher,$this->module);
$this->init_vector= mcrypt_create_iv($this->cip_block_size,MCRYPT_DEV_RANDOM);
}
public function setCipherModule($cip,$mod)
{
$this->cipher=$cip;
$this->module=$mod;
$this->cip_block_size= mcrypt_get_block_size ($this->cipher,$this->module);
$this->init_vector= mcrypt_create_iv($this->cip_block_size,MCRYPT_DEV_RANDOM);
}
public function encrypt($str,$key)
{
$this->str='';
$this->str=mcrypt_cbc($this->cipher, $key, $str,$this->mode_enc,$this->init_vector);
return $this->encode($this->str);
}
public function decrypt($str,$key)
{
$this->str='';
$this->str=$this->decode($str);
return mcrypt_cbc($this->cipher,
$key,$this->str,$this->mode_dec,$this->init_vector);
}
public function encode($input)
{
return (base64_encode($input));//Base64 encode Technique
}
public function decode($input)
{
return (base64_decode($input)); //Base64 decode Technique
}
public function hash($algo,$data)
{
return @hash($algo,$data); //Hash with algorithm
}
}
$obj=new bscrypt();
$str=$obj->encrypt('Dhaka University of Engineering Technology','DUET');
echo $str."<br>";
echo $obj->decrypt($str,'DUET');
?>