note 112147 added to classobj.examples
| From: | hafiz at bhuiyansoft dot com | Date: | Fri, 10 May 2013 08:33:43 +0000 |
| Subject: | note 112147 added to classobj.examples | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194758@lists.php.net to get a copy of this message | ||
<?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');
?>
----
Server IP: 69.147.83.199
Probable Submitter: 180.149.25.87
----
Manual Page -- http://php.net/manual/en/classobj.examples.php
Edit -- https://master.php.net/note/edit/112147
Del: integrated -- https://master.php.net/note/delete/112147/integrated
Del: useless -- https://master.php.net/note/delete/112147/useless
Del: bad code -- https://master.php.net/note/delete/112147/bad+code
Del: spam -- https://master.php.net/note/delete/112147/spam
Del: non-english -- https://master.php.net/note/delete/112147/non-english
Del: in docs -- https://master.php.net/note/delete/112147/in+docs
Del: other reasons-- https://master.php.net/note/delete/112147
Reject -- https://master.php.net/note/reject/112147
Search -- https://master.php.net/manage/user-notes.php