Skip to content

Commit 43b514b

Browse files
authored
Merge pull request #7 from peter279k/fix_key
Fix key is same on different Encryption classes
2 parents 9bc7740 + e2245a1 commit 43b514b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Encryption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class Encryption
4545
*/
4646
public function __construct($key, $adapter = null)
4747
{
48-
($adapter !== null) ? $this->setAdapter($adapter) : $this->setAdapter('openssl');
4948
$this->setKey($key);
49+
($adapter !== null) ? $this->setAdapter($adapter) : $this->setAdapter('openssl');
5050
}
5151

5252
/**

tests/EncryptionTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222

2323
class EncryptionTest extends TestCase
2424
{
25+
public function testEncryptAndDecryptOnDifferentKeyWithOpenSsl()
26+
{
27+
$encryption = new Encryption('12345678990-=====-===', 'openssl');
28+
$encryptedString = $encryption->encrypt('plain-text');
29+
30+
$encryption2 = new Encryption('different_key', 'openssl');
31+
$decryptedString = $encryption2->decrypt($encryptedString);
32+
33+
$this->assertFalse($decryptedString);
34+
}
35+
2536
public function testEncryptAndDecryptWithOpenSsl()
2637
{
2738
$encryption = new Encryption('12345678990-=====-===', 'openssl');

0 commit comments

Comments
 (0)