CoreFiles by mySites.guru
Hash.php61 lines, 1,322 bytes, from Joomla_5.3.2-Stable-Full_Package.zip
Raw History Compare with 5.3.1
md5
17015ff840bc714c397c51e9b9fc199d
sha1
e44163f94c8b14f1f27dbe4c466c586848b2750b
sha256
2448bf4a850caea20d7c06b33a87772bdeda7e7ca04a53631e4d821e25e43d7e
<?php

declare(strict_types=1);

namespace Jose\Component\Core\Util;

/**
 * @internal
 */
final class Hash
{
    private function __construct(
        private readonly string $hash,
        private readonly int $length,
        private readonly string $t
    ) {
    }

    public static function sha1(): self
    {
        return new self('sha1', 20, "\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14");
    }

    public static function sha256(): self
    {
        return new self('sha256', 32, "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20");
    }

    public static function sha384(): self
    {
        return new self('sha384', 48, "\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02\x05\x00\x04\x30");
    }

    public static function sha512(): self
    {
        return new self('sha512', 64, "\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03\x05\x00\x04\x40");
    }

    public function getLength(): int
    {
        return $this->length;
    }

    /**
     * Compute the HMAC.
     */
    public function hash(string $text): string
    {
        return hash($this->hash, $text, true);
    }

    public function name(): string
    {
        return $this->hash;
    }

    public function t(): string
    {
        return $this->t;
    }
}

The same content is in 136 releases, Joomla 5.1.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.