6 V4.01 23 Oct 2003 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
7 Contributed by Ross Smith (adodb@netebb.com).
8 Released under both BSD license and Lesser GPL library license.
9 Whenever there is any discrepancy between the two licenses,
10 the BSD license will take precedence.
11 Set tabs to 4 for best viewing.
15 if (!function_exists('mcrypt_encrypt')) {
16 trigger_error('Mcrypt functions are not available', E_USER_ERROR
);
22 class ADODB_Encrypt_MCrypt
{
37 function getCipher() {
38 return $this->_cipher
;
43 function setCipher($cipher) {
44 $this->_cipher
= $cipher;
55 function setMode($mode) {
61 function getSource() {
62 return $this->_source
;
67 function setSource($source) {
68 $this->_source
= $source;
73 function ADODB_Encrypt_MCrypt($cipher = null, $mode = null, $source = null) {
75 $cipher = MCRYPT_RIJNDAEL_256
;
78 $mode = MCRYPT_MODE_ECB
;
81 $source = MCRYPT_RAND
;
84 $this->_cipher
= $cipher;
86 $this->_source
= $source;
91 function write($data, $key) {
92 $iv_size = mcrypt_get_iv_size($this->_cipher
, $this->_mode
);
93 $iv = mcrypt_create_iv($iv_size, $this->_source
);
94 return mcrypt_encrypt($this->_cipher
, $key, $data, $this->_mode
, $iv);
99 function read($data, $key) {
100 $iv_size = mcrypt_get_iv_size($this->_cipher
, $this->_mode
);
101 $iv = mcrypt_create_iv($iv_size, $this->_source
);
102 $rv = mcrypt_decrypt($this->_cipher
, $key, $data, $this->_mode
, $iv);
103 return rtrim($rv, "\0");