Soshot/app/Utils/Hmac.php

37 lines
830 B
PHP
Raw Normal View History

2023-06-21 11:42:36 +02:00
<?php
namespace App\Utils;
class Hmac {
private $key;
private $basePath = __DIR__ . '/../../cache/img/';
private $filePath;
private $hashPath;
public function __construct($key) {
$this->key = $key;
}
public function makeHmac($url) {
return hash_hmac('sha1', $url, $this->key);
}
private function makeHashPath($hashUrl) {
$this->hashPath = substr($hashUrl, 0, 4) . '/';
return $this->hashPath;
}
public function makeFilePath($hmac) {
$this->filePath = $this->basePath . $this->makeHashPath($hmac);
return $this->filePath;
}
public function checkHmac($receiveHmac, $url) {
if ($receiveHmac === $this->makeHmac($url, $this->key)) {
return true;
} else {
return false;
}
}
}