34 if (!is_string($string)) {
35 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException(
'A hash can only be generated for a string, but "' . gettype($string) .
'" was given.', 1255069587);
37 $encryptionKey =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'];
38 if (!$encryptionKey) {
39 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException(
'Encryption Key was empty!', 1255069597);
41 return hash_hmac(
'sha1', $string, $encryptionKey);
55 return $string . $hmac;
85 if (!is_string($string)) {
86 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException(
'A hash can only be validated for a string, but "' . gettype($string) .
'" was given.', 1320829762);
88 if (strlen($string) < 40) {
89 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException(
'A hashed string must contain at least 40 characters, the given string was only ' . strlen($string) .
' characters long.', 1320830276);
91 $stringWithoutHmac = substr($string, 0, -40);
92 if ($this->
validateHmac($stringWithoutHmac, substr($string, -40)) !==
true) {
93 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidHashException(
'The given string was not appended with a valid HMAC.', 1320830018);
95 return $stringWithoutHmac;