HashService implements SingletonInterface

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

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

Internal

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

Table of Contents

Interfaces

SingletonInterface
"empty" interface for singletons (marker interface pattern)

Methods

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.

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

Tags
throws
InvalidArgumentForHashGenerationException

if something else than a string was given as parameter

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