Search code examples
phplaravelaes

laravel AES key generation without updating env file


I am using php artisan key:generate for generating AES key,but it updating env file each time.

I need to generate a unique AES key for a chatroom.

Any suggestion will be appreciated.


Solution

  • If you take a look at the source of this command, you can find the function that is used to generate this key. If you want to use this key for something else, you can reuse this function.

    protected function generateRandomKey()
    {
        return 'base64:'.base64_encode(
            Encrypter::generateKey($this->laravel['config']['app.cipher'])
        );
    }