Collection report bug fix and an internationalization issue fix
[openemr.git] / library / adodb / session / adodb-encrypt-mcrypt.php
blobcb21d12a4631f6ccb3e275c1f39a323470b5d074
1 <?php
3 // $CVSHeader$
5 /*
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);
17 return 0;
20 /**
22 class ADODB_Encrypt_MCrypt {
23 /**
25 var $_cipher;
27 /**
29 var $_mode;
31 /**
33 var $_source;
35 /**
37 function getCipher() {
38 return $this->_cipher;
41 /**
43 function setCipher($cipher) {
44 $this->_cipher = $cipher;
47 /**
49 function getMode() {
50 return $this->_mode;
53 /**
55 function setMode($mode) {
56 $this->_mode = $mode;
59 /**
61 function getSource() {
62 return $this->_source;
65 /**
67 function setSource($source) {
68 $this->_source = $source;
71 /**
73 function ADODB_Encrypt_MCrypt($cipher = null, $mode = null, $source = null) {
74 if (!$cipher) {
75 $cipher = MCRYPT_RIJNDAEL_256;
77 if (!$mode) {
78 $mode = MCRYPT_MODE_ECB;
80 if (!$source) {
81 $source = MCRYPT_RAND;
84 $this->_cipher = $cipher;
85 $this->_mode = $mode;
86 $this->_source = $source;
89 /**
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);
97 /**
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");
108 return 1;