17 lines
592 B
PHP
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);
|
|
}
|
|
} |