5 V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
6 Contributed by Ross Smith (adodb@netebb.com).
7 Released under both BSD license and Lesser GPL library license.
8 Whenever there is any discrepancy between the two licenses,
9 the BSD license will take precedence.
10 Set tabs to 4 for best viewing.
14 if (!function_exists('mcrypt_encrypt')) {
15 trigger_error('Mcrypt functions are not available', E_USER_ERROR
);
21 class ADODB_Encrypt_MCrypt
{
36 function getCipher() {
37 return $this->_cipher
;
42 function setCipher($cipher) {
43 $this->_cipher
= $cipher;
54 function setMode($mode) {
60 function getSource() {
61 return $this->_source
;
66 function setSource($source) {
67 $this->_source
= $source;
72 function ADODB_Encrypt_MCrypt($cipher = null, $mode = null, $source = null) {
74 $cipher = MCRYPT_RIJNDAEL_256
;
77 $mode = MCRYPT_MODE_ECB
;
80 $source = MCRYPT_RAND
;
83 $this->_cipher
= $cipher;
85 $this->_source
= $source;
90 function write($data, $key) {
91 $iv_size = mcrypt_get_iv_size($this->_cipher
, $this->_mode
);
92 $iv = mcrypt_create_iv($iv_size, $this->_source
);
93 return mcrypt_encrypt($this->_cipher
, $key, $data, $this->_mode
, $iv);
98 function read($data, $key) {
99 $iv_size = mcrypt_get_iv_size($this->_cipher
, $this->_mode
);
100 $iv = mcrypt_create_iv($iv_size, $this->_source
);
101 $rv = mcrypt_decrypt($this->_cipher
, $key, $data, $this->_mode
, $iv);
102 return rtrim($rv, "\0");