decryptData() public method

Decrypts the given data (string) using the regarding php-extension, depending on the library assigned to algorithm in the contructor.
public decryptData ( string $data ) : mixed | string
$data string
return mixed | string
Example #1
0
 /**
  * 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).
  *
  * @param XMLSecurityKey $objKey  The decryption key that should be used when decrypting the node.
  * @param boolean        $replace Whether we should replace the encrypted node in the XML document with the decrypted data. The default is true.
  *
  * @return string|DOMElement  The decrypted data.
  */
 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");
     }
 }