You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel@11加密错误求助:不支持的加密算法或密钥长度问题

Laravel 11 加密相关错误求助

错误信息

Unsupported cipher or incorrect key length. Supported ciphers are: aes-128-cbc, aes-256-cbc, aes-128-gcm, aes-256-gcm.

错误截图显示页面顶部弹出上述加密错误提示。

运行环境

  • Windows 11
  • PHP 8.2.4
  • Laravel 11

composer.json 内容

{"name": "laravel/laravel","type": "project","description": "The skeleton application for the Laravel framework.","keywords": ["laravel","framework"],"license": "MIT","require": {"php": "^8.2","inertiajs/inertia-laravel": "^1.0","laravel/framework": "^11.0","laravel/reverb": "@beta","laravel/sanctum": "^4.0","laravel/tinker": "^2.9","tightenco/ziggy": "^2.0"},"require-dev": {"fakerphp/faker": "^1.23","laravel/breeze": "^2.0","laravel/pint": "^1.13","laravel/sail": "^1.26","mockery/mockery": "^1.6","nunomaduro/collision": "^8.0","pestphp/pest": "^2.0","pestphp/pest-plugin-laravel": "^2.0","spatie/laravel-ignition": "^2.4"},"autoload": {"psr-4": {"App\\": "app/","Database\\Factories\\": "database/factories/","Database\\Seeders\\": "database/seeders/"}},"autoload-dev": {"psr-4": {"Tests\\": "tests/"}},"scripts": {"post-autoload-dump": ["Illuminate\\Foundation\\ComposerScripts::postAutoloadDump","@php artisan package:discover --ansi"],"post-update-cmd": ["@php artisan vendor:publish --tag=laravel-assets --ansi --force"],"post-root-package-install": ["@php -r \"file_exists('.env') || copy('.env.example', '.env');\""],"post-create-project-cmd": ["@php artisan key:generate --ansi","@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"","@php artisan migrate --graceful --ansi"]},"extra": {"laravel": {"dont-discover": []}},"config": {"optimize-autoloader": true,"preferred-install": "dist","sort-packages": true,"allow-plugins": {"pestphp/pest-plugin": true,"php-http/discovery": true}},"minimum-stability": "stable","prefer-stable": true}

已尝试自行解决但未成功,寻求可行的修复方案。


解决方案参考

  1. 重置应用密钥并确认加密算法

    • 执行命令重新生成符合要求的应用密钥:
      php artisan key:generate
      
    • 打开.env文件,确认APP_CIPHER值为以下支持的算法之一:aes-128-cbc、aes-256-cbc、aes-128-gcm、aes-256-gcm,Laravel 11默认使用aes-256-gcm。
  2. 清除配置缓存

    • 运行命令确保新配置生效:
      php artisan config:clear
      php artisan cache:clear
      
  3. 验证PHP扩展

    • 检查PHP是否安装openssl扩展,执行php -m查看扩展列表,若缺失需在PHP配置中启用该扩展。
  4. 确认.env文件有效性

    • 确保.env文件位于项目根目录,且系统有读取权限,可通过php artisan env命令验证环境配置是否正确加载。

内容的提问来源于stack exchange,提问作者Yousuf Ahamad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 11:57:49