From b87a5cb81d85fb7399ec19dd597deddc18dfd26f Mon Sep 17 00:00:00 2001 From: cajus Date: Thu, 6 Dec 2007 08:49:38 +0000 Subject: [PATCH] Removed base64 encoding git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8038 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_socketClient.inc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/include/class_socketClient.inc b/include/class_socketClient.inc index da54da5a8..bf0b79522 100755 --- a/include/class_socketClient.inc +++ b/include/class_socketClient.inc @@ -28,13 +28,14 @@ class Socket_Client public function SetEncryptionKey($data) { + $data= str_pad($data, 32, $data); if(!function_exists("mcrypt_get_iv_size")){ $this->error = _("The mcrypt module was not found. Please install php5-mcrypt.") ; return(FALSE); }else{ $this->encrypt = TRUE; $this->crypt_key= $data; - $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $this->iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); return(TRUE); } @@ -44,17 +45,16 @@ class Socket_Client { /* Encrypt data */ if($this->encrypt){ - $data = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $this->crypt_key, $data, MCRYPT_MODE_ECB, $this->iv); + $data = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $this->crypt_key, $data, MCRYPT_MODE_CBC, $this->iv); } - return(base64_encode($data)); + return($data); } private function decrypt($data) { - $data = base64_decode($data); /* decrypt data */ if($this->encrypt){ - $data = mcrypt_decrypt (MCRYPT_RIJNDAEL_256, $this->crypt_key, $data, MCRYPT_MODE_ECB, $this->iv); + $data = mcrypt_decrypt (MCRYPT_RIJNDAEL_256, $this->crypt_key, $data, MCRYPT_MODE_CBC, $this->iv); $data = rtrim($data,"\x00"); } return($data); @@ -87,10 +87,11 @@ class Socket_Client public function send($data) { + $data= str_repeat("0", 16 - strlen($data)%16).$data; if($this->handle){ $data = $this->encrypt($data); $data = trim($data); - fputs($this->handle,$data."\n"); + fputs($this->handle, $data."\n"); $this->b_data_send = TRUE; return(TRUE); }else{ @@ -125,7 +126,7 @@ class Socket_Client $this->b_data_send = FALSE; $str = $this->decrypt($str); } - return($str); + return(preg_replace('/^0*/', '', $str)); } public function read() -- 2.30.2