public function XMLSecEnc::decryptNode in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 8
Decrypt this encrypted node.
The behaviour of this function depends on the value of $replace. If $replace is false, we will return the decrypted data as a string. If $replace is true, we will insert the decrypted element(s) into the document, and return the decrypted element(s).
Parameters
XMLSecurityKey $objKey The decryption key that should be used when decrypting the node.:
boolean $replace Whether we should replace the encrypted node in the XML document with the decrypted data. The default is true.:
Return value
string|DOMElement The decrypted data.
1 call to XMLSecEnc::decryptNode()
File
- src/
XMLSecurityKey.php, line 2025
Class
Namespace
Drupal\miniorange_samlCode
public function decryptNode($objKey, $replace = true) {
if (!$objKey instanceof XMLSecurityKey) {
throw new Exception('Invalid Key');
}
$encryptedData = $this
->getCipherValue();
if ($encryptedData) {
$decrypted = $objKey
->decryptData($encryptedData);
if ($replace) {
switch ($this->type) {
case self::Element:
$newdoc = new DOMDocument();
$newdoc
->loadXML($decrypted);
if ($this->rawNode->nodeType == XML_DOCUMENT_NODE) {
return $newdoc;
}
$importEnc = $this->rawNode->ownerDocument
->importNode($newdoc->documentElement, true);
$this->rawNode->parentNode
->replaceChild($importEnc, $this->rawNode);
return $importEnc;
case self::Content:
if ($this->rawNode->nodeType == XML_DOCUMENT_NODE) {
$doc = $this->rawNode;
}
else {
$doc = $this->rawNode->ownerDocument;
}
$newFrag = $doc
->createDocumentFragment();
$newFrag
->appendXML($decrypted);
$parent = $this->rawNode->parentNode;
$parent
->replaceChild($newFrag, $this->rawNode);
return $parent;
default:
return $decrypted;
}
}
else {
return $decrypted;
}
}
else {
throw new Exception("Cannot locate encrypted data");
}
}