2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
26 function manageurs_encrypt_init($id_assoce){
27 global $tripledes, $globals;
28 $cipher_key = $globals->manageurs
->manageurs_cipher_key
;
30 if(empty($cipher_key)){
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);
40 function manageurs_encrypt_close(){
43 mcrypt_generic_deinit($tripledes);
44 mcrypt_module_close($tripledes);
49 function manageurs_encrypt($message){
51 if (empty($message)) {
54 return base64_encode(mcrypt_generic($tripledes, utf8_decode($message)));
57 function manageurs_decrypt($message){
59 return trim(mdecrypt_generic($tripledes, base64_decode($message)));
62 function manageurs_encrypt_array($array){
63 foreach($array as $key => $value){
65 $result[manageurs_encrypt($key)] = manageurs_encrypt_array($value);
68 $result[manageurs_encrypt($key)] = manageurs_encrypt($value);
74 function manageurs_decrypt_array($array){
75 foreach($array as $key => $value){
77 $result[manageurs_decrypt($key)] = manageurs_decrypt_array($value);
80 $result[manageurs_decrypt($key)] = manageurs_decrypt($value);
86 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: