Initial commit: CABM-IT (ItGlue-style MSP documentation platform)
Laravel 13 + Livewire/Volt app for managing client organizations, documents, passwords, flexible assets, virtual machines, contacts, domains, todos, shortcuts, and role-based user administration.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
||||
/**
|
||||
* AES-256-GCM encrypt/decrypt via the app's Crypt facade.
|
||||
*
|
||||
* Simplification: uses the single app-wide key as the encryption key (KEK == DEK).
|
||||
* Production hardening: wrap a per-organization DEK with a KMS-held KEK (envelope
|
||||
* encryption) so a single leaked app key doesn't expose every tenant's secrets.
|
||||
*/
|
||||
class EncryptedField implements CastsAttributes
|
||||
{
|
||||
public function get($model, string $key, $value, array $attributes)
|
||||
{
|
||||
if ($value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Crypt::decryptString($value);
|
||||
} catch (\Illuminate\Contracts\Encryption\DecryptException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function set($model, string $key, $value, array $attributes)
|
||||
{
|
||||
return $value === null ? null : Crypt::encryptString($value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user