2 namespace TYPO3\CMS\Extbase\Security\Cryptography;
35 if (!is_string($string)) {
36 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException(
'A hash can only be generated for a string, but "' . gettype($string) .
'" was given.', 1255069587);
38 $encryptionKey =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'];
39 if (!$encryptionKey) {
40 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException(
'Encryption Key was empty!', 1255069597);
42 return hash_hmac(
'sha1', $string, $encryptionKey);
56 return $string . $hmac;
86 if (!is_string($string)) {
87 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException(
'A hash can only be validated for a string, but "' . gettype($string) .
'" was given.', 1320829762);
89 if (strlen($string) < 40) {
90 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);
92 $stringWithoutHmac = substr($string, 0, -40);
93 if ($this->
validateHmac($stringWithoutHmac, substr($string, -40)) !==
true) {
94 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidHashException(
'The given string was not appended with a valid HMAC.', 1320830018);
96 return $stringWithoutHmac;