From a8a99bd617317f0e4207521bd1db1b5114655c7c Mon Sep 17 00:00:00 2001 From: Tugrul Topuz Date: Wed, 21 Dec 2016 12:31:22 +0300 Subject: [PATCH 1/2] Phalcon\Crypt safe base64 padding Added autopadding feature for following methods - Phalcon\Crypt::encryptBase64 - Phalcon\Crypt::decryptBase64 --- phalcon/crypt.zep | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phalcon/crypt.zep b/phalcon/crypt.zep index fa89a40e59c..eed0669e02c 100644 --- a/phalcon/crypt.zep +++ b/phalcon/crypt.zep @@ -372,7 +372,7 @@ class Crypt implements CryptInterface public function encryptBase64(string! text, key = null, boolean! safe = false) -> string { if safe == true { - return strtr(base64_encode(this->encrypt(text, key)), "+/", "-_"); + return rtrim(strtr(base64_encode(this->encrypt(text, key)), "+/", "-_"), '='); } return base64_encode(this->encrypt(text, key)); } @@ -383,7 +383,7 @@ class Crypt implements CryptInterface public function decryptBase64(string! text, key = null, boolean! safe = false) -> string { if safe == true { - return this->decrypt(base64_decode(strtr(text, "-_", "+/")), key); + return this->decrypt(base64_decode(strtr(text, "-_", "+/") . substr('===', (strlen(text) + 3) % 4)), key); } return this->decrypt(base64_decode(text), key); } From cf4f3b84af95364271762d1f0af095e752c22d30 Mon Sep 17 00:00:00 2001 From: Tugrul Topuz Date: Wed, 21 Dec 2016 12:46:14 +0300 Subject: [PATCH 2/2] Crypt base64 string fix --- phalcon/crypt.zep | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phalcon/crypt.zep b/phalcon/crypt.zep index eed0669e02c..eec9a67213c 100644 --- a/phalcon/crypt.zep +++ b/phalcon/crypt.zep @@ -372,7 +372,7 @@ class Crypt implements CryptInterface public function encryptBase64(string! text, key = null, boolean! safe = false) -> string { if safe == true { - return rtrim(strtr(base64_encode(this->encrypt(text, key)), "+/", "-_"), '='); + return rtrim(strtr(base64_encode(this->encrypt(text, key)), "+/", "-_"), "="); } return base64_encode(this->encrypt(text, key)); } @@ -383,7 +383,7 @@ class Crypt implements CryptInterface public function decryptBase64(string! text, key = null, boolean! safe = false) -> string { if safe == true { - return this->decrypt(base64_decode(strtr(text, "-_", "+/") . substr('===', (strlen(text) + 3) % 4)), key); + return this->decrypt(base64_decode(strtr(text, "-_", "+/") . substr("===", (strlen(text) + 3) % 4)), key); } return this->decrypt(base64_decode(text), key); }