note 96637 added to function.mcrypt-cbc
| From: | filip dot pytloun at ifrit dot eu | Date: | Tue, 09 Mar 2010 15:02:38 +0000 |
| Subject: | note 96637 added to function.mcrypt-cbc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166828@lists.php.net to get a copy of this message | ||
This simple class could be useful for people who want to work with mcrypt-cbc more often.
<?php
/**
* @author Filip Pytloun
* @copyright 2010
*/
class Crypter {
private $key;
private $cipher;
/**
* @param string $key
* @param string $cipher
* @return bool
*/
public function __construct($key = '', $cipher = 'MCRYPT_3DES') {
$this->key = $key;
$this->cipher = $cipher;
return true;
}
/**
* @param string $key
* @return bool
*/
public function setKey($key) {
$this->key = $key;
return true;
}
/**
* @param string $cipher
* return bool
*/
public function setCipher($cipher) {
$this->cipher = $cipher;
return true;
}
/**
* @param string $d_string
* @param string $key
* @param string $cipher
* @return string
*/
public function encrypt($d_string, $key = '', $cipher = '') {
if (empty($key)) {
$key = $this->key;
}
if (empty($cipher)) {
$cipher = $this->cipher;
}
$e_string = mcrypt_cbc($cipher,$key,$d_string,MCRYPT_ENCRYPT);
return $e_string;
}
/**
* @param string $e_string
* @param string $key
* @param string $cipher
* @return string
*/
public function decrypt($e_string, $key = '', $cipher = '') {
if (empty($key)) {
$key = $this->key;
}
if (empty($cipher)) {
$cipher = $this->cipher;
}
$d_string = mcrypt_cbc($cipher,$key,$d_string,MCRYPT_DECRYPT);
return $d_string;
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 95.143.130.173
----
Manual Page -- http://www.php.net/manual/en/function.mcrypt-cbc.php
Edit -- https://master.php.net/note/edit/96637
Del: integrated -- https://master.php.net/note/delete/96637/integrated
Del: useless -- https://master.php.net/note/delete/96637/useless
Del: bad code -- https://master.php.net/note/delete/96637/bad+code
Del: spam -- https://master.php.net/note/delete/96637/spam
Del: non-english -- https://master.php.net/note/delete/96637/non-english
Del: in docs -- https://master.php.net/note/delete/96637/in+docs
Del: other reasons-- https://master.php.net/note/delete/96637
Reject -- https://master.php.net/note/reject/96637
Search -- https://master.php.net/manage/user-notes.php