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

**Code:** `Unsupported cipher or incorrect key length` · **Category:** Laravel · **Seen on:** Laravel, PHP

`APP_KEY` is missing, malformed or empty, or `config/app.php` cipher doesn't match the key length.

## Meaning

Generate a key with `php artisan key:generate` (writes `base64:...` to `.env`). Check that `.env` exists on the server, the key line has no spaces/quotes issues, and config isn't cached with an old/empty key. AES-256 needs 32 bytes; a 16-char key with `AES-256-CBC` fails.

## Common causes

- APP_KEY empty (no .env on server)
- Key not base64-prefixed or wrong length
- Config cached before the key existed
- `.env` has `APP_KEY=` with spaces
- Cipher changed in config/app.php

## Quick fix

1. `php artisan key:generate`
2. `php artisan config:clear`
3. Confirm `.env` is present and readable by the web user

## Detailed fix by platform

### Laravel

1. `php artisan key:generate --force && php artisan config:cache`

## How to diagnose

1. **.env** — Present?
2. **Key** — base64 32 bytes?
3. **Cache** — Rebuilt?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/laravel/unsupported-cipher-incorrect-key-length)
