From e2245a17ecc75261ec691eb663cf2c0cf8296e00 Mon Sep 17 00:00:00 2001 From: peter279k Date: Sun, 23 Feb 2020 16:06:07 +0800 Subject: [PATCH] Fix key is same on different Encryption classes --- src/Encryption.php | 2 +- tests/EncryptionTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Encryption.php b/src/Encryption.php index c6d2389..830bd91 100644 --- a/src/Encryption.php +++ b/src/Encryption.php @@ -45,8 +45,8 @@ class Encryption */ public function __construct($key, $adapter = null) { - ($adapter !== null) ? $this->setAdapter($adapter) : $this->setAdapter('openssl'); $this->setKey($key); + ($adapter !== null) ? $this->setAdapter($adapter) : $this->setAdapter('openssl'); } /** diff --git a/tests/EncryptionTest.php b/tests/EncryptionTest.php index fb5d969..0277070 100644 --- a/tests/EncryptionTest.php +++ b/tests/EncryptionTest.php @@ -22,6 +22,17 @@ class EncryptionTest extends TestCase { + public function testEncryptAndDecryptOnDifferentKeyWithOpenSsl() + { + $encryption = new Encryption('12345678990-=====-===', 'openssl'); + $encryptedString = $encryption->encrypt('plain-text'); + + $encryption2 = new Encryption('different_key', 'openssl'); + $decryptedString = $encryption2->decrypt($encryptedString); + + $this->assertFalse($decryptedString); + } + public function testEncryptAndDecryptWithOpenSsl() { $encryption = new Encryption('12345678990-=====-===', 'openssl');