domovoy/app/Services/Security/CredentialVault.php

32 lines
675 B
PHP

<?php
declare(strict_types=1);
namespace Domovoy\Services\Security;
use Defuse\Crypto\Crypto;
class CredentialVault
{
private string $password;
public function __construct(string $keyMaterial)
{
if (trim($keyMaterial) === '') {
throw new \InvalidArgumentException('ENCRYPTION_KEY is required');
}
$this->password = $keyMaterial;
}
public function encrypt(string $plainText): string
{
return Crypto::encryptWithPassword($plainText, $this->password);
}
public function decrypt(string $cipherText): string
{
return Crypto::decryptWithPassword($cipherText, $this->password);
}
}