source: Dev/trunk/rdfapi/util/adodb/session/adodb-encrypt-mcrypt.php @ 12

Last change on this file since 12 was 12, checked in by basvannuland, 14 years ago

Added RAP RDF API
Added RDF reader writer for save and load survey

File size: 1.9 KB
Line 
1<?php
2
3
4/*
5V4.94 23 Jan 2007  (c) 2000-2007 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
14if (!function_exists('mcrypt_encrypt')) {
15        trigger_error('Mcrypt functions are not available', E_USER_ERROR);
16        return 0;
17}
18
19/**
20 */
21class 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
107return 1;
108
109?>
Note: See TracBrowser for help on using the repository browser.