appendHmac() public method

Appends a hash (HMAC) to a given string and returns the result
See also: generateHmac()
public appendHmac ( string $string ) : string
$string string The string for which a hash should be generated
return string The original string with HMAC of the string appended
Example #1
0
 /**
  * Renders hidden form fields for referrer information about
  * the current request.
  *
  * @return string Hidden fields with referrer information
  */
 protected function renderHiddenReferrerFields()
 {
     $tagBuilder = new TagBuilder('input');
     $tagBuilder->addAttribute('type', 'hidden');
     $tagBuilder->addAttribute('name', $this->prefixFieldName('__state'));
     $serializedFormState = base64_encode(serialize($this->arguments['object']->getFormState()));
     $tagBuilder->addAttribute('value', $this->hashService->appendHmac($serializedFormState));
     return $tagBuilder->render();
 }
 /**
  * @test
  */
 public function validateAndStripHmacReturnsTheStringWithoutHmac()
 {
     $string = ' Some arbitrary string with special characters: öäüß!"§$ ';
     $hashedString = $this->hashService->appendHmac($string);
     $actualResult = $this->hashService->validateAndStripHmac($hashedString);
     $this->assertSame($string, $actualResult);
 }
 /**
  * Renders hidden form fields for referrer information about
  * the current controller and action.
  *
  * @return string Hidden fields with referrer information
  * @todo filter out referrer information that is equal to the target (e.g. same packageKey)
  */
 protected function renderHiddenReferrerFields()
 {
     $result = chr(10);
     $request = $this->controllerContext->getRequest();
     $argumentNamespace = null;
     if (!$request->isMainRequest()) {
         $argumentNamespace = $request->getArgumentNamespace();
         $referrer = array('@package' => $request->getControllerPackageKey(), '@subpackage' => $request->getControllerSubpackageKey(), '@controller' => $request->getControllerName(), '@action' => $request->getControllerActionName(), 'arguments' => $this->hashService->appendHmac(base64_encode(serialize($request->getArguments()))));
         foreach ($referrer as $referrerKey => $referrerValue) {
             $referrerValue = htmlspecialchars($referrerValue);
             $result .= '<input type="hidden" name="' . $argumentNamespace . '[__referrer][' . $referrerKey . ']" value="' . $referrerValue . '" />' . chr(10);
         }
         $request = $request->getParentRequest();
     }
     $arguments = $request->getArguments();
     if ($argumentNamespace !== null && isset($arguments[$argumentNamespace])) {
         // A sub request was there; thus we can unset the sub requests arguments,
         // as they are transferred separately via the code block shown above.
         unset($arguments[$argumentNamespace]);
     }
     $referrer = array('@package' => $request->getControllerPackageKey(), '@subpackage' => $request->getControllerSubpackageKey(), '@controller' => $request->getControllerName(), '@action' => $request->getControllerActionName(), 'arguments' => $this->hashService->appendHmac(base64_encode(serialize($arguments))));
     foreach ($referrer as $referrerKey => $referrerValue) {
         $result .= '<input type="hidden" name="__referrer[' . $referrerKey . ']" value="' . htmlspecialchars($referrerValue) . '" />' . chr(10);
     }
     return $result;
 }
 /**
  * Get the URI for an AJAX Request.
  *
  * @return string the AJAX URI
  * @throws WidgetContextNotFoundException
  */
 protected function getAjaxUri()
 {
     $action = $this->arguments['action'];
     $arguments = $this->arguments['arguments'];
     if ($action === null) {
         $action = $this->controllerContext->getRequest()->getControllerActionName();
     }
     $arguments['@action'] = $action;
     if (strlen($this->arguments['format']) > 0) {
         $arguments['@format'] = $this->arguments['format'];
     }
     /** @var $widgetContext WidgetContext */
     $widgetContext = $this->controllerContext->getRequest()->getInternalArgument('__widgetContext');
     if ($widgetContext === null) {
         throw new WidgetContextNotFoundException('Widget context not found in <f:widget.link>', 1307450686);
     }
     if ($this->arguments['includeWidgetContext'] === true) {
         $serializedWidgetContext = serialize($widgetContext);
         $arguments['__widgetContext'] = $this->hashService->appendHmac($serializedWidgetContext);
     } else {
         $arguments['__widgetId'] = $widgetContext->getAjaxWidgetIdentifier();
     }
     return '?' . http_build_query($arguments, null, '&');
 }
 /**
  * Serialize and hash the form field array
  *
  * @param array $formFieldArray form field array to be serialized and hashed
  * @return string Hash
  */
 protected function serializeAndHashFormFieldArray($formFieldArray)
 {
     $serializedFormFieldArray = serialize($formFieldArray);
     return $this->hashService->appendHmac($serializedFormFieldArray);
 }