GenericHash class

Framework\Crypto\GenericHash

Class GenericHash.

Defined in libraries/crypto/src/GenericHash.php

Properties #

$key
-
$hashLength
-

$key

protected string $key

$hashLength

protected int $hashLength = 32

Methods #

__construct()
GenericHash constructor.
makeKey()
Makes a key.
signature()
Gets a message signature.
verify()
Verifies if a message matches a signature.
makeHash()
Makes a hash to a message.
validateHashLength()
Validates a hash length.
validateKey()
Validates a key.

__construct()

public function __construct(string $key, int $hashLength = 32)

GenericHash constructor.

Parameters
  • string $key
  • int $hashLength
throws
LengthException if key length is not between 16 and 64
throws
RangeException if the hashLength value is not in the range 16 to 64

makeKey()

public static function makeKey(): string

Makes a key.

Returns string

signature()

public function signature(string $message, ?int $hashLength = NULL): string

Gets a message signature.

Parameters
  • string $message
  • ?int $hashLength - A custom hash length or null to use the length set in the constructor
Returns string
throws
RangeException if the hashLength is set and is not in the range 16 to 64
throws
SodiumException

verify()

public function verify(string $message, string $signature, ?int $hashLength = NULL): bool

Verifies if a message matches a signature.

Parameters
  • string $message
  • string $signature
  • ?int $hashLength - A custom hash length or null to use the length set in the constructor
Returns bool
throws
RangeException if the hashLength is set and is not in the range 16 to 64
throws
SodiumException

makeHash()

protected function makeHash(string $message, ?int $length = NULL): string

Makes a hash to a message.

Parameters
  • string $message
  • ?int $length - A custom length or null to use the length set in the constructor
Returns string
throws
RangeException if the length is set and is not in the range 16 to 64
throws
SodiumException

validateHashLength()

protected function validateHashLength(int $length): void

Validates a hash length.

Parameters
  • int $length
Returns void
throws
RangeException if the length value is not in the range 16 to 64

validateKey()

protected function validateKey(string $key): void

Validates a key.

Parameters
  • string $key
Returns void
throws
LengthException if key length is not between 16 and 64