3 * @author Jan Altensen (Stricted)
4 * @copyright 2013-2014 Jan Altensen (Stricted)
5 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
33 * constructor to validate algorithm
40 public function __construct ($algo, $raw = '', $hmac = '', $key = '') {
45 if (in_array($algo, hash_algos())) {
49 die("algorithm ".$algo." not supported");
54 * hash given data with given algorithm
59 public function hash ($data) {
60 if (!empty($this->hmac
)) {
61 return hash_hmac($this->algo
, $data, $this->key
, $this->raw
);
64 return hash($this->algo
, $data, $this->raw
);
69 * hash given file with given algorithm
74 public function hash_file ($file) {
75 if (!empty($this->hmac
)) {
76 return hash_hmac_file($this->algo
, $file, $this->key
, $this->raw
);
79 return hash_file($this->algo
, $file, $this->raw
);
84 * compare the given data
90 public function compare ($hash, $data) {
91 $newhash = $this->hash($data);
93 if ($newhash == $hash) {
101 * compare the given file
103 * @param string $hash
104 * @param string $file
107 public function compare_file ($hash, $file) {
108 $newhash = $this->hash_file($file);
110 if ($newhash == $hash) {