Why is EnvironmentEncryptCommand not using LARAVEL_ENV_ENCRYPTION_KEY #58359
Replies: 2 comments 4 replies
-
|
Maybe because it asks for a key? Update see below the logical reason. |
Beta Was this translation helpful? Give feedback.
-
Analysis of the Encryption Key InconsistencyPosted via Claude Code I wanted to provide a more detailed analysis of this API inconsistency, as I believe the original point raised deserves stronger consideration. The Core ProblemLooking at the two commands:
This creates an asymmetric API where two closely related commands behave differently for the same optional parameter pattern. Why This Matters1. Principle of Least Surprise When both commands accept 2. Real-World Use Cases Consider a developer who:
They would expect this to use their existing key. Instead, they get a new random key, which means they now need to update their deployment configuration unnecessarily. 3. The "Random Key" Default Has Sharp Edges If someone runs the encrypt command without carefully capturing the output, they have created an encrypted file they can never decrypt. While the command does display the key, this UX pattern is more error-prone than checking for an existing key first. Proposed SolutionA simple change to $key = $this->option("key")
?? env("LARAVEL_ENV_ENCRYPTION_KEY")
?? Encrypter::generateKey($this->parseEncryptionCipher());This approach:
Addressing the Counter-ArgumentThe argument that "encrypt runs locally, decrypt runs in production" describes a typical workflow but not the only valid workflow. The beauty of Laravel's optional parameters is flexibility—and that flexibility should be consistent across related commands. If the commands were designed to be used in fundamentally different contexts, the decrypt command wouldn't need to accept a I believe this is worth a PR. The code change is minimal, the reasoning is sound, and it would improve developer experience without any breaking changes. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The EnvironmentDecryptCommand is using
LARAVEL_ENV_ENCRYPTION_KEYbut the EnvironmentEncryptCommand is not?I don't see a reason why?
So if I encrypt without a key, it seems to use a random string, while I would expect
LARAVEL_ENV_ENCRYPTION_KEYto be used ?Beta Was this translation helpful? Give feedback.
All reactions