Fixes vim mode line.
[platal.git] / include / webservices / manageurs.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 Polytechnique.org *
0337d704 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
26function 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
40function manageurs_encrypt_close(){
41 global $tripledes;
42 if($tripledes){
43 mcrypt_generic_deinit($tripledes);
44 mcrypt_module_close($tripledes);
45 $tripledes = '';
46 }
47}
48
49function manageurs_encrypt($message){
50 global $tripledes;
206e75c3 51 if (empty($message)) {
52 return $message;
53 }
54 return base64_encode(mcrypt_generic($tripledes, utf8_decode($message)));
0337d704 55}
56
57function manageurs_decrypt($message){
58 global $tripledes;
59 return trim(mdecrypt_generic($tripledes, base64_decode($message)));
60}
61
62function manageurs_encrypt_array($array){
63 foreach($array as $key => $value){
64 if(is_array($value)){
65 $result[manageurs_encrypt($key)] = manageurs_encrypt_array($value);
66 }
67 else{
68 $result[manageurs_encrypt($key)] = manageurs_encrypt($value);
69 }
70 }
71 return $result;
72}
73
74function manageurs_decrypt_array($array){
75 foreach($array as $key => $value){
76 if(is_array($value)){
77 $result[manageurs_decrypt($key)] = manageurs_decrypt_array($value);
78 }
79 else{
80 $result[manageurs_decrypt($key)] = manageurs_decrypt($value);
81 }
82 }
83 return $result;
84}
85
448c8cdc 86// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
0337d704 87?>