CoreFiles by mySites.guru
Hasher.php36 lines, 1,155 bytes, from Joomla_6.2.0-Stable-Full_Package.zip
Raw History Compare with 6.1.4
md5
3df425d83045b581e0e3e16cd0823ed7
sha1
cddce654f71bcde2d120cf27a38380821e099892
sha256
9978b9130ab443a9926de5ed1090d874d68af17a97ba4db9a484666684da32cf
<?php

declare(strict_types=1);

namespace AltchaOrg\Altcha\Hasher;

class Hasher implements HasherInterface
{
    public function hash(Algorithm $algorithm, string $data): string
    {
        return match ($algorithm) {
            Algorithm::SHA1 => sha1($data, true),
            Algorithm::SHA256 => hash('sha256', $data, true),
            Algorithm::SHA512 => hash('sha512', $data, true),
        };
    }

    public function hashHex(Algorithm $algorithm, string $data): string
    {
        return bin2hex($this->hash($algorithm, $data));
    }

    public function hashHmac(Algorithm $algorithm, string $data, #[\SensitiveParameter] string $hmacKey): string
    {
        return match ($algorithm) {
            Algorithm::SHA1 => hash_hmac('sha1', $data, $hmacKey, true),
            Algorithm::SHA256 => hash_hmac('sha256', $data, $hmacKey, true),
            Algorithm::SHA512 => hash_hmac('sha512', $data, $hmacKey, true),
        };
    }

    public function hashHmacHex(Algorithm $algorithm, string $data, #[\SensitiveParameter] string $hmacKey): string
    {
        return bin2hex($this->hashHmac($algorithm, $data, $hmacKey));
    }
}

The same content is in 32 releases, Joomla 6.1.0-alpha2 to 6.3.0-alpha1. See them all, or every version of this file.