Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
36 kaklik 1
<?php
2
 
3
 
4
/*
5
V4.80 8 Mar 2006  (c) 2000-2006 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.
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
 
19
/**
20
 */
21
class ADODB_Encrypt_MCrypt {
22
	/**
23
	 */
24
	var $_cipher;
25
 
26
	/**
27
	 */
28
	var $_mode;
29
 
30
	/**
31
	 */
32
	var $_source;
33
 
34
	/**
35
	 */
36
	function getCipher() {
37
		return $this->_cipher;
38
	}
39
 
40
	/**
41
	 */
42
	function setCipher($cipher) {
43
		$this->_cipher = $cipher;
44
	}
45
 
46
	/**
47
	 */
48
	function getMode() {
49
		return $this->_mode;
50
	}
51
 
52
	/**
53
	 */
54
	function setMode($mode) {
55
		$this->_mode = $mode;
56
	}
57
 
58
	/**
59
	 */
60
	function getSource() {
61
		return $this->_source;
62
	}
63
 
64
	/**
65
	 */
66
	function setSource($source) {
67
		$this->_source = $source;
68
	}
69
 
70
	/**
71
	 */
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
 
88
	/**
89
	 */
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
 
96
	/**
97
	 */
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;
108
 
109
?>