Custom encryption key #47686
Unanswered
omaresmael
asked this question in
Ideas
Replies: 2 comments 1 reply
-
I think this is a good idea. |
Beta Was this translation helpful? Give feedback.
1 reply
-
The key should be 32bit. This is how Laravel decrypts the base64 key to use in the crypt. $key = config('app.key'); // you can make the app to generate new key and use it instead
if (Str::startsWith($key, 'base64:')) {
$key = base64_decode(substr($key, 7));
}
$newEncrypter = new \Illuminate\Encryption\Encrypter($key, config('app.cipher'));
$encrypted = $newEncrypter->encrypt($plainTextToEncrypt);
$decrypted = $newEncrypter->decrypt($encrypted); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey,
I recently came across a use-case where I needed to use a custom encryption key instead of the default one ('key' => env('APP_KEY')). After some exploration, I found this thread on the Laracast that provided a workaround.
However, I've been thinking of making a pr to allow the
encrypt
anddecrypt
helper functions to accept an optional$key
parameter. By passing a specific key as an argument, theEncrypter
would use that key for encryption/decryption. If no key is provided, theEncrypter
would fallback to the default encryption key.would you like to see a pr for that or do you have something else in mind
please let me know
thank you
Beta Was this translation helpful? Give feedback.
All reactions