You are here

public function XMLSecurityDSig::sign in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 7

Parameters

XMLSecurityKey $objKey:

null|DOMNode $appendToNode:

File

includes/XMLSecurityKey.php, line 1528

Class

XMLSecurityDSig

Code

public function sign($objKey, $appendToNode = null) {

  // If we have a parent node append it now so C14N properly works
  if ($appendToNode != null) {
    $this
      ->resetXPathObj();
    $this
      ->appendSignature($appendToNode);
    $this->sigNode = $appendToNode->lastChild;
  }
  if ($xpath = $this
    ->getXPathObj()) {
    $query = "./secdsig:SignedInfo";
    $nodeset = $xpath
      ->query($query, $this->sigNode);
    if ($sInfo = $nodeset
      ->item(0)) {
      $query = "./secdsig:SignatureMethod";
      $nodeset = $xpath
        ->query($query, $sInfo);
      $sMethod = $nodeset
        ->item(0);
      $sMethod
        ->setAttribute('Algorithm', $objKey->type);
      $data = $this
        ->canonicalizeData($sInfo, $this->canonicalMethod);
      $sigValue = base64_encode($this
        ->signData($objKey, $data));
      $sigValueNode = $this
        ->createNewSignNode('SignatureValue', $sigValue);
      if ($infoSibling = $sInfo->nextSibling) {
        $infoSibling->parentNode
          ->insertBefore($sigValueNode, $infoSibling);
      }
      else {
        $this->sigNode
          ->appendChild($sigValueNode);
      }
    }
  }
}