Home > Enterprise >  how to get the 32bit secret encryption key from laravel env file
how to get the 32bit secret encryption key from laravel env file

Time:02-18

I am trying to fetch the secret encryption key from laravel so that I can use it on the mobile app end for decrypting the data. When I run the command in the laravel

php artisan key:generate

It created the below key in the .env file in laravel. Laravel documentation says that the above command should create a 32 character string key but i get the blow string

APP_KEY=base64:H2gjrkZZAx3U6Rc7hhZG59xzNY2bSsaW1dKpo1Q1NRk=

Larvel uses the above key to encrypt the data. I need the 32 character key string to decrypt the data in other places. Above Key after removing base64: is 44 character string so I get this is not the actual string. I have tried to decode the string by using base64_decode but then it gives a binary string. I need the actual 32 character secret key

Can someone please guide how do I fetch the actual secret key string so that I can use it in other places for decrypting the data?

Regards Syed

CodePudding user response:

If you base64 decode H2gjrkZZAx3U6Rc7hhZG59xzNY2bSsaW1dKpo1Q1NRk= it returns a 32 character long string (binary).

But generally I would think you could use native Laravel methods for decryption and thus avoid fetching the key manually.

CodePudding user response:

If I understand you very well, go to your "config/app.php"

Change 'cipher' => 'AES-256-CBC',to AES-128-CBC and then re-generate the key.

  • Related