Files
workbloomerp-backend/app/Shared/Utils/CypherUtil.php
T
Claudecio Martins a951944997 first commit
2026-06-16 10:04:10 -03:00

17 lines
592 B
PHP

<?php
namespace WorkbloomERP\Utils;
use Exception;
class CypherUtil {
public static function hash(string $data): string {
if (!isset($_ENV['SYSTEM_CYPHER_ALGO']) || !isset($_ENV['SYSTEM_CYPHER_PEPPER'])) {
throw new Exception('Missing required environment variables for hashing');
}
return hash_hmac(algo: $_ENV['SYSTEM_CYPHER_ALGO'], data: $data, key: $_ENV['SYSTEM_CYPHER_PEPPER']);
}
public static function verify(string $data, string $hash): bool {
return hash_equals(known_string: self::hash($data), user_string: $hash);
}
}