From 384beac150960fb1e013949e051b552bffd2c916 Mon Sep 17 00:00:00 2001 From: iomcr <> Date: Wed, 2 Feb 2022 15:56:41 -0500 Subject: [PATCH 1/3] Use Illuminate\Support\Arr for compatibility. --- src/Encrypter.php | 7 ++++--- src/Providers/EncryptionServiceProvider.php | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Encrypter.php b/src/Encrypter.php index f9f3d0d..e57f054 100644 --- a/src/Encrypter.php +++ b/src/Encrypter.php @@ -2,6 +2,7 @@ namespace LaravelAEAD; +use Illuminate\Support\Arr; use LaravelAEAD\Ciphers; use LaravelAEAD\Contracts\Encrypter as EncrypterContract; use LaravelAEAD\Exceptions\DecryptException; @@ -134,7 +135,7 @@ protected function decodePayload(string $payload) : array $payload = json_decode($this->decodeBase64($payload), true); // the payload should at least contain the 3 main keys. - if (!array_has($payload, ['value', 'nonce', 'ad'])) { + if (!Arr::has($payload, ['value', 'nonce', 'ad'])) { throw new DecryptException('Invalid Payload.'); } @@ -258,7 +259,7 @@ public static function getCiphers(): array public static function getCipherClass(string $cipherName): string { // retrieves the list of available ciphers - $cipherClass = array_get(self::getCiphers(), $cipherName, null); + $cipherClass = Arr::get(self::getCiphers(), $cipherName, null); // check if the cipher exists. if (!$cipherClass || !class_exists($cipherClass)) { @@ -268,4 +269,4 @@ public static function getCipherClass(string $cipherName): string // returns the cipher class. return $cipherClass; } -} \ No newline at end of file +} diff --git a/src/Providers/EncryptionServiceProvider.php b/src/Providers/EncryptionServiceProvider.php index e6fbc8c..67b935d 100644 --- a/src/Providers/EncryptionServiceProvider.php +++ b/src/Providers/EncryptionServiceProvider.php @@ -5,6 +5,7 @@ use LaravelAEAD\Encrypter; use Illuminate\Encryption\Encrypter as LaravelEncrypter; use Illuminate\Encryption\EncryptionServiceProvider as LaravelEncryptionServiceProvider; +use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Contracts\Config\Repository as Config; @@ -52,7 +53,7 @@ public function register() */ protected function supported(string $cipher) : bool { - return array_has(Encrypter::getCiphers(), $cipher); + return Arr::has(Encrypter::getCiphers(), $cipher); } /** @@ -80,4 +81,4 @@ protected function getConfigValue(string $key, $default = null) // retrieve the value for the key, return $value; } -} \ No newline at end of file +} From edb6835715109c3782b1e2917df4eab0dd9b7032 Mon Sep 17 00:00:00 2001 From: iomcr <> Date: Wed, 2 Feb 2022 15:59:37 -0500 Subject: [PATCH 2/3] remove old dependancy --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f084d2d..cd85efe 100644 --- a/composer.json +++ b/composer.json @@ -24,8 +24,7 @@ "require": { "php": ">=7.2.0", "ext-sodium": "*", - "ext-json": "*", - "illuminate/support": "^5.6" + "ext-json": "*" }, "require-dev": { "phpunit/phpunit": "^7.0", From 7c34aa94509ff3390e28dfdafb1042aee058eeb3 Mon Sep 17 00:00:00 2001 From: InstanceOfMichael Date: Tue, 8 Feb 2022 10:53:59 -0500 Subject: [PATCH 3/3] Support Laravel 7. I did not test this with versions of `laravel/framework` past `^7.29`. It's just that the framework now requires the `getKey` function. --- src/Encrypter.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Encrypter.php b/src/Encrypter.php index e57f054..7a10347 100644 --- a/src/Encrypter.php +++ b/src/Encrypter.php @@ -37,6 +37,11 @@ class Encrypter implements EncrypterContract */ protected $cipher; + /** + * @var string $key + */ + protected $key; + /** * Create a new encrypter instance. * @@ -51,6 +56,8 @@ public function __construct($key, $cipherName = 'XCHACHA20-POLY1305-IETF') // force the key into string. $key = (string)$key; + $this->key = $key; + // create the instance of the cipher. $this->cipher = self::makeCipher($key, $cipherName); } @@ -269,4 +276,8 @@ public static function getCipherClass(string $cipherName): string // returns the cipher class. return $cipherClass; } + + public function getKey(): string { + return $this->key; + } }