first commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user