updated adodb package to work with php 7.1
[openemr.git] / vendor / adodb / adodb-php / session / adodb-encrypt-mcrypt.php
blobfc99fbc29c0017f794fecd70f134ff2bb490dc1e
1 <?php
4 /*
5 @version v5.20.9 21-Dec-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.
16 if (!function_exists('mcrypt_encrypt')) {
17 trigger_error('Mcrypt functions are not available', E_USER_ERROR);
18 return 0;
21 /**
23 class ADODB_Encrypt_MCrypt {
24 /**
26 var $_cipher;
28 /**
30 var $_mode;
32 /**
34 var $_source;
36 /**
38 function getCipher() {
39 return $this->_cipher;
42 /**
44 function setCipher($cipher) {
45 $this->_cipher = $cipher;
48 /**
50 function getMode() {
51 return $this->_mode;
54 /**
56 function setMode($mode) {
57 $this->_mode = $mode;
60 /**
62 function getSource() {
63 return $this->_source;
66 /**
68 function setSource($source) {
69 $this->_source = $source;
72 /**
74 function __construct($cipher = null, $mode = null, $source = null) {
75 if (!$cipher) {
76 $cipher = MCRYPT_RIJNDAEL_256;
78 if (!$mode) {
79 $mode = MCRYPT_MODE_ECB;
81 if (!$source) {
82 $source = MCRYPT_RAND;
85 $this->_cipher = $cipher;
86 $this->_mode = $mode;
87 $this->_source = $source;
90 /**
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);
98 /**
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");
109 return 1;