From 2768a975d7627b4929ae6fa4c25eb0141bc160d5 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 28 Nov 2014 16:34:20 +0200 Subject: [PATCH 1/2] fix crypt --- application/Espo/Core/Utils/Crypt.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/application/Espo/Core/Utils/Crypt.php b/application/Espo/Core/Utils/Crypt.php index 8d4e591232..e4cba62bb7 100644 --- a/application/Espo/Core/Utils/Crypt.php +++ b/application/Espo/Core/Utils/Crypt.php @@ -29,6 +29,8 @@ class Crypt private $key = null; private $cryptKey = null; + + private $iv = null; public function __construct($config) { @@ -43,15 +45,28 @@ class Crypt } return $this->key; } + + protected function getIv() + { + if (empty($this->iv)) { + $this->iv = mcrypt_create_iv(16, MCRYPT_RAND); + } + return $this->iv; + } public function encrypt($string) { - return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->getKey(), $string, MCRYPT_MODE_CBC)); + $iv = $this->getIv(); + return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->getKey(), $string, MCRYPT_MODE_CBC, $iv) . $iv); } public function decrypt($encryptedString) { - return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->getKey(), base64_decode($encryptedString), MCRYPT_MODE_CBC)); + $encryptedString = base64_decode($encryptedString); + + $string = substr($encryptedString, 0, strlen($encryptedString) - 16); + $iv = substr($encryptedString, -16); + return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->getKey(), $string, MCRYPT_MODE_CBC, $iv)); } public function generateKey() From bdeaaa796537daa68bf8365e41b487b4b3a96192 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 1 Dec 2014 11:00:37 +0200 Subject: [PATCH 2/2] version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ced96d384d..ec5f630f35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "espocrm", - "version": "2.7.1", + "version": "2.7.2", "description": "", "main": "index.php", "repository": "",