2006 => 2007 Happy New Year\!
[platal.git] / include / webservices / manageurs.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22
23 $tripledes = '';
24
25
26 function manageurs_encrypt_init($id_assoce){
27 global $tripledes, $globals;
28 $cipher_key = $globals->manageurs->manageurs_cipher_key;
29 if(!$tripledes){
30 if(empty($cipher_key)){
31 return 1;
32 }
33 $tripledes = mcrypt_module_open('tripledes', '', 'ecb', '');
34 $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($tripledes), MCRYPT_RAND);
35 mcrypt_generic_init($tripledes, $cipher_key.$id_assoce, $iv);
36 return 0;
37 }
38 }
39
40 function manageurs_encrypt_close(){
41 global $tripledes;
42 if($tripledes){
43 mcrypt_generic_deinit($tripledes);
44 mcrypt_module_close($tripledes);
45 $tripledes = '';
46 }
47 }
48
49 function manageurs_encrypt($message){
50 global $tripledes;
51 return base64_encode(mcrypt_generic($tripledes, $message));
52 }
53
54 function manageurs_decrypt($message){
55 global $tripledes;
56 return trim(mdecrypt_generic($tripledes, base64_decode($message)));
57 }
58
59 function manageurs_encrypt_array($array){
60 foreach($array as $key => $value){
61 if(is_array($value)){
62 $result[manageurs_encrypt($key)] = manageurs_encrypt_array($value);
63 }
64 else{
65 $result[manageurs_encrypt($key)] = manageurs_encrypt($value);
66 }
67 }
68 return $result;
69 }
70
71 function manageurs_decrypt_array($array){
72 foreach($array as $key => $value){
73 if(is_array($value)){
74 $result[manageurs_decrypt($key)] = manageurs_decrypt_array($value);
75 }
76 else{
77 $result[manageurs_decrypt($key)] = manageurs_decrypt($value);
78 }
79 }
80 return $result;
81 }
82
83 ?>