TYPO3 CMS  TYPO3_7-6
adodb-encrypt-mcrypt.php
Go to the documentation of this file.
1 <?php
2 
3 
4 /*
5 @version v5.20.3 01-Jan-2016
6 @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
7 @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
8  Contributed by Ross Smith (adodb@netebb.com).
9  Released under both BSD license and Lesser GPL library license.
10  Whenever there is any discrepancy between the two licenses,
11  the BSD license will take precedence.
12  Set tabs to 4 for best viewing.
13 
14 */
15 
16 if (!function_exists('mcrypt_encrypt')) {
17  trigger_error('Mcrypt functions are not available', E_USER_ERROR);
18  return 0;
19 }
20 
26  var $_cipher;
27 
30  var $_mode;
31 
34  var $_source;
35 
38  function getCipher() {
39  return $this->_cipher;
40  }
41 
44  function setCipher($cipher) {
45  $this->_cipher = $cipher;
46  }
47 
50  function getMode() {
51  return $this->_mode;
52  }
53 
56  function setMode($mode) {
57  $this->_mode = $mode;
58  }
59 
62  function getSource() {
63  return $this->_source;
64  }
65 
68  function setSource($source) {
69  $this->_source = $source;
70  }
71 
74  function __construct($cipher = null, $mode = null, $source = null) {
75  if (!$cipher) {
76  $cipher = MCRYPT_RIJNDAEL_256;
77  }
78  if (!$mode) {
79  $mode = MCRYPT_MODE_ECB;
80  }
81  if (!$source) {
82  $source = MCRYPT_RAND;
83  }
84 
85  $this->_cipher = $cipher;
86  $this->_mode = $mode;
87  $this->_source = $source;
88  }
89 
92  function write($data, $key) {
93  $iv_size = mcrypt_get_iv_size($this->_cipher, $this->_mode);
94  $iv = mcrypt_create_iv($iv_size, $this->_source);
95  return mcrypt_encrypt($this->_cipher, $key, $data, $this->_mode, $iv);
96  }
97 
100  function read($data, $key) {
101  $iv_size = mcrypt_get_iv_size($this->_cipher, $this->_mode);
102  $iv = mcrypt_create_iv($iv_size, $this->_source);
103  $rv = mcrypt_decrypt($this->_cipher, $key, $data, $this->_mode, $iv);
104  return rtrim($rv, "\0");
105  }
106 
107 }
108 
109 return 1;
if(!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE' E_USER_ERROR
__construct($cipher=null, $mode=null, $source=null)