简体   繁体   English

如何从 laravel env 文件中获取 32 位秘密加密密钥

[英]how to get the 32bit secret encryption key from laravel env file

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.我正在尝试从 laravel 获取秘密加密密钥,以便我可以在移动应用程序端使用它来解密数据。 When I run the command in the laravel当我在 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它在 laravel 的 .env 文件中创建了以下密钥。Laravel 文档说上面的命令应该创建一个 32 个字符的字符串密钥,但我得到了打击字符串

APP_KEY=base64:H2gjrkZZAx3U6Rc7hhZG59xzNY2bSsaW1dKpo1Q1NRk= APP_KEY=base64:H2gjrkZZAx3U6Rc7hhZG59xzNY2bSsaW1dKpo1Q1NRk=

Larvel uses the above key to encrypt the data. Larvel 使用上述密钥来加密数据。 I need the 32 character key string to decrypt the data in other places.我需要32个字符的密钥字符串来解密其他地方的数据。 Above Key after removing base64: is 44 character string so I get this is not the actual string.删除 base64 后,上面的键是 44 个字符的字符串,所以我得到这不是实际的字符串。 I have tried to decode the string by using base64_decode but then it gives a binary string.我尝试使用 base64_decode 解码字符串,但随后它给出了一个二进制字符串。 I need the actual 32 character secret key我需要实际的 32 个字符的密钥

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问候赛义德

If you base64 decode H2gjrkZZAx3U6Rc7hhZG59xzNY2bSsaW1dKpo1Q1NRk= it returns a 32 character long string (binary).如果你 base64 解码 H2gjrkZZAx3U6Rc7hhZG59xzNY2bSsaW1dKpo1Q1NRk= 它返回一个 32 个字符长的字符串(二进制)。

But generally I would think you could use native Laravel methods for decryption and thus avoid fetching the key manually.但通常我认为您可以使用本机 Laravel 方法进行解密,从而避免手动获取密钥。

If I understand you very well, go to your "config/app.php"如果我很了解你,go 到你的“config/app.php”

Change 'cipher' => 'AES-256-CBC', to AES-128-CBC and then re-generate the key.'cipher' => 'AES-256-CBC',更改为AES-128-CBC ,然后重新生成密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM