encrypter()->encryptString($plain); } public function decrypt(string $cipher): string { return $this->encrypter()->decryptString($cipher); } /** Is storing credentials possible at all on this installation? */ public function isUsable(): bool { return (string) config('admin_access.secrets_key') !== ''; } private function encrypter(): Encrypter { $key = (string) config('admin_access.secrets_key'); if ($key === '') { throw new RuntimeException('SECRETS_KEY is not set — refusing to store or read credentials.'); } if (str_starts_with($key, 'base64:')) { $key = substr($key, 7); } if (strlen($key) !== 32) { $decoded = base64_decode($key, true); if ($decoded !== false && strlen($decoded) === 32) { $key = $decoded; } } if (strlen($key) !== 32) { throw new RuntimeException('SECRETS_KEY must be 32 bytes (or base64 of 32 bytes).'); } return new Encrypter($key, 'aes-256-cbc'); } }