diff --git a/packages/cryptography/src/Encryption/EncryptionKey.php b/packages/cryptography/src/Encryption/EncryptionKey.php index 0f4cb16c65..e6a88e7247 100644 --- a/packages/cryptography/src/Encryption/EncryptionKey.php +++ b/packages/cryptography/src/Encryption/EncryptionKey.php @@ -16,7 +16,7 @@ public function __construct( } if (strlen($value) !== $algorithm->getKeyLength()) { - throw EncryptionKeyWasInvalid::becauseLengthMismatched($algorithm); + throw EncryptionKeyWasInvalid::becauseLengthMismatched($algorithm, strlen($value)); } } diff --git a/packages/cryptography/src/Encryption/Exceptions/EncryptionKeyWasInvalid.php b/packages/cryptography/src/Encryption/Exceptions/EncryptionKeyWasInvalid.php index 317201ff2a..2bd7cfb299 100644 --- a/packages/cryptography/src/Encryption/Exceptions/EncryptionKeyWasInvalid.php +++ b/packages/cryptography/src/Encryption/Exceptions/EncryptionKeyWasInvalid.php @@ -16,14 +16,17 @@ public function __construct( public static function becauseItIsMissing(EncryptionAlgorithm $algorithm): self { - return new self('The encryption key is missing or empty. Ensure you have a `SIGNING_KEY` environment variable.', $algorithm); + return new self( + message: 'The encryption key is missing or empty. Generate a valid `SIGNING_KEY` with `php tempest key:generate`.', + algorithm: $algorithm, + ); } - public static function becauseLengthMismatched(EncryptionAlgorithm $algorithm): self + public static function becauseLengthMismatched(EncryptionAlgorithm $algorithm, int $actualLength): self { return new self( - "The encryption key length does not match the expected length ({$algorithm->getKeyLength()}).", - $algorithm, + message: "The encryption key length ({$actualLength}) does not match the expected length ({$algorithm->getKeyLength()}). Generate a valid `SIGNING_KEY` with `php tempest key:generate`.", + algorithm: $algorithm, ); } } diff --git a/packages/cryptography/src/GenerateSigningKeyCommand.php b/packages/cryptography/src/GenerateSigningKeyCommand.php index fb22a76594..f65b1da33c 100644 --- a/packages/cryptography/src/GenerateSigningKeyCommand.php +++ b/packages/cryptography/src/GenerateSigningKeyCommand.php @@ -21,7 +21,11 @@ public function __construct( private Console $console, ) {} - #[ConsoleCommand('key:generate', description: 'Generates the signing key required to sign and verify data.')] + #[ConsoleCommand( + name: 'key:generate', + description: 'Generates the signing key required to sign and verify data.', + aliases: ['generate:key'], + )] public function __invoke(bool $override = true): ExitCode { $key = EncryptionKey::generate($this->encryptionConfig->algorithm); diff --git a/packages/cryptography/src/Signing/Exceptions/SigningKeyWasInvalid.php b/packages/cryptography/src/Signing/Exceptions/SigningKeyWasInvalid.php index 45d5dfd95d..211bdc05dc 100644 --- a/packages/cryptography/src/Signing/Exceptions/SigningKeyWasInvalid.php +++ b/packages/cryptography/src/Signing/Exceptions/SigningKeyWasInvalid.php @@ -8,6 +8,6 @@ final class SigningKeyWasInvalid extends Exception implements SigningException { public static function becauseItIsMissing(): self { - return new self('The signing key is missing or empty. Ensure you have a `SIGNING_KEY` environment variable.'); + return new self('The signing key is missing or empty. Generate a valid `SIGNING_KEY` with `php tempest key:generate`.'); } }