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", diff --git a/src/Encrypter.php b/src/Encrypter.php index f9f3d0d..7a10347 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; @@ -36,6 +37,11 @@ class Encrypter implements EncrypterContract */ protected $cipher; + /** + * @var string $key + */ + protected $key; + /** * Create a new encrypter instance. * @@ -50,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); } @@ -134,7 +142,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 +266,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 +276,8 @@ public static function getCipherClass(string $cipherName): string // returns the cipher class. return $cipherClass; } -} \ No newline at end of file + + public function getKey(): string { + return $this->key; + } +} 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 +}