<?php
namespace App\Support\Security;
use Illuminate\Contracts\Encryption\Encrypter; use RuntimeException;
final class LaravelEnvelopeEncryption implements EnvelopeEncryption { public function __construct(private Encrypter $encrypter){} public function encrypt(string $plaintext,array $context=[]): array { if(app()->environment('production')&&!config('gateway.security.allow_local_encryption_in_production')) throw new RuntimeException('KMS-backed envelope encryption is required in production.'); return ['ciphertext'=>$this->encrypter->encryptString($plaintext),'kid'=>'local-app-key','context'=>$context]; } public function decrypt(array $payload,array $context=[]): string { return $this->encrypter->decryptString($payload['ciphertext']); } }
