TYPO3 CMS  TYPO3_6-2
adodb-encrypt-mcrypt.php
Go to the documentation of this file.
1 <?php
2 
3 
4 /*
5 V5.19 23-Apr-2014 (c) 2000-2014 John Lim (jlim#natsoft.com). 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.
11 
12 */
13 
14 if (!function_exists('mcrypt_encrypt')) {
15  trigger_error('Mcrypt functions are not available', E_USER_ERROR);
16  return 0;
17 }
18 
24  var $_cipher;
25 
28  var $_mode;
29 
32  var $_source;
33 
36  function getCipher() {
37  return $this->_cipher;
38  }
39 
42  function setCipher($cipher) {
43  $this->_cipher = $cipher;
44  }
45 
48  function getMode() {
49  return $this->_mode;
50  }
51 
54  function setMode($mode) {
55  $this->_mode = $mode;
56  }
57 
60  function getSource() {
61  return $this->_source;
62  }
63 
66  function setSource($source) {
67  $this->_source = $source;
68  }
69 
72  function ADODB_Encrypt_MCrypt($cipher = null, $mode = null, $source = null) {
73  if (!$cipher) {
74  $cipher = MCRYPT_RIJNDAEL_256;
75  }
76  if (!$mode) {
77  $mode = MCRYPT_MODE_ECB;
78  }
79  if (!$source) {
80  $source = MCRYPT_RAND;
81  }
82 
83  $this->_cipher = $cipher;
84  $this->_mode = $mode;
85  $this->_source = $source;
86  }
87 
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);
94  }
95 
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");
103  }
104 
105 }
106 
107 return 1;
ADODB_Encrypt_MCrypt($cipher=null, $mode=null, $source=null)
if(!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE' E_USER_ERROR