‪TYPO3CMS  ‪main
TYPO3\CMS\Extbase\Security\Cryptography\HashService Class Reference

Public Member Functions

 __construct (protected readonly CoreHashService $hashService)
 
string generateHmac (string $string)
 
string appendHmac (string $string)
 
bool validateHmac (string $string, string $hmac)
 
string validateAndStripHmac (string $string)
 

Detailed Description

A hash service which should be used to generate and validate hashes.

It will use some salt / encryption key in the future.

only to be used within Extbase, not part of TYPO3 Core API.

Deprecated:
‪will be removed in TYPO3 v14.0. Use \TYPO3\CMS\Core\Crypto\HashService instead.

Note: Remove used exception codes in AbstractExceptionHandler::IGNORED_HMAC_EXCEPTION_CODES in v14.0

Definition at line 34 of file HashService.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Extbase\Security\Cryptography\HashService::__construct ( protected readonly CoreHashService  $hashService)

Definition at line 36 of file HashService.php.

Member Function Documentation

◆ appendHmac()

string TYPO3\CMS\Extbase\Security\Cryptography\HashService::appendHmac ( string  $string)

Appends a hash (HMAC) to a given string and returns the result

Parameters
string$string‪The string for which a hash should be generated
Returns
‪string The original string with HMAC of the string appended
See also
generateHmac()
Todo:
‪Mark as API once it is more stable

Definition at line 61 of file HashService.php.

◆ generateHmac()

string TYPO3\CMS\Extbase\Security\Cryptography\HashService::generateHmac ( string  $string)

Generate a hash (HMAC) for a given string

Parameters
string$string‪The string for which a hash should be generated
Returns
‪string The hash of the string

Definition at line 44 of file HashService.php.

◆ validateAndStripHmac()

string TYPO3\CMS\Extbase\Security\Cryptography\HashService::validateAndStripHmac ( string  $string)

Tests if the last 40 characters of a given string $string matches the HMAC of the rest of the string and, if true, returns the string without the HMAC. In case of a HMAC validation error, an exception is thrown.

Parameters
string$string‪The string with the HMAC appended (in the format 'string<HMAC>')
Returns
‪string the original string without the HMAC, if validation was successful
See also
validateHmac()
Exceptions

Definition at line 99 of file HashService.php.

References TYPO3\CMS\Extbase\Security\Cryptography\HashService\validateHmac().

◆ validateHmac()

bool TYPO3\CMS\Extbase\Security\Cryptography\HashService::validateHmac ( string  $string,
string  $hmac 
)

Tests if a string $string matches the HMAC given by $hash.

Parameters
string$string‪The string which should be validated
string$hmac‪The hash of the string
Returns
‪bool TRUE if string and hash fit together, FALSE otherwise.

Definition at line 77 of file HashService.php.

Referenced by TYPO3\CMS\Extbase\Security\Cryptography\HashService\validateAndStripHmac().