在 CentOS 上,Laravel 的“加密”通常指两件事,下面分别说明,你可以按需求选择。
Laravel 自带加密功能,不依赖系统环境。
cd /path/to/laravel
php artisan key:generate
生成后会写入 .env:
APP_KEY=base64:xxxxxxxxxxxxxxxx
use Illuminate\Support\Facades\Crypt;
// 加密
$encrypted = Crypt::encryptString('secret');
// 解密
$decrypted = Crypt::decryptString($encrypted);
✅ 使用的是 AES-256-CBC
CentOS 上常用 Nginx + SSL
yum install nginx -y
yum install certbot python3-certbot-nginx -y
certbot --nginx -d example.com
.env
APP_URL=https://example.com
在 Model 中使用:
protected $casts = [
'card_number' => 'encrypted',
];
INSERT INTO users (name, email)
VALUES (AES_ENCRYPT('tom', 'key'), 'a@b.com');
⚠️ 不推荐,维护复杂
Storage::put('secret.txt', Crypt::encryptString('data'));
cryptsetup luksFormat /dev/sdb
❗ 仅适合服务器安全加固
✅ Laravel 项目加密 = APP_KEY + Crypt 类
✅ 网络安全 = HTTPS
✅ 敏感字段 = encrypted cast
如果你说的是:
可以直接告诉我,我给你具体方案。