HashService

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

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

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

Internal

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

Attributes
#[Autoconfigure]
$public: true

Table of Contents

Properties

$hashService  : HashService

Methods

__construct()  : mixed
appendHmac()  : string
Appends a hash (HMAC) to a given string and returns the result
generateHmac()  : string
Generate a hash (HMAC) for a given string
validateAndStripHmac()  : 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.
validateHmac()  : bool
Tests if a string $string matches the HMAC given by $hash.

Properties

Methods

appendHmac()

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

public appendHmac(string $string) : string
Parameters
$string : string

The string for which a hash should be generated

Tags
see
generateHmac()
todo

Mark as API once it is more stable

Return values
string —

The original string with HMAC of the string appended

generateHmac()

Generate a hash (HMAC) for a given string

public generateHmac(string $string) : string
Parameters
$string : string

The string for which a hash should be generated

Return values
string —

The hash of the string

validateAndStripHmac()

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.

public validateAndStripHmac(string $string) : string
Parameters
$string : string

The string with the HMAC appended (in the format 'string<HMAC>')

Tags
see
validateHmac()
throws
InvalidArgumentForHashGenerationException

if the given string is not well-formatted

throws
InvalidHashException

if the hash did not fit to the data.

todo

Mark as API once it is more stable

Return values
string —

the original string without the HMAC, if validation was successful

validateHmac()

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

public validateHmac(string $string, string $hmac) : bool
Parameters
$string : string

The string which should be validated

$hmac : string

The hash of the string

Return values
bool —

TRUE if string and hash fit together, FALSE otherwise.


        
On this page

Search results