RobRichards\XMLSecLibs\XMLSecurityKey::encryptData PHP Method

encryptData() public method

Encrypts the given data (string) using the regarding php-extension, depending on the library assigned to algorithm in the contructor.
public encryptData ( string $data ) : mixed | string
$data string
return mixed | string
    public function encryptData($data)
    {
        switch ($this->cryptParams['library']) {
            case 'mcrypt':
                return $this->encryptMcrypt($data);
            case 'openssl':
                return $this->encryptOpenSSL($data);
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Encrypt the XMLSecurityKey
  *
  * @param XMLSecurityKey $srcKey
  * @param XMLSecurityKey $rawKey
  * @param bool $append
  * @throws Exception
  */
 public function encryptKey($srcKey, $rawKey, $append = true)
 {
     if (!$srcKey instanceof XMLSecurityKey || !$rawKey instanceof XMLSecurityKey) {
         throw new Exception('Invalid Key');
     }
     $strEncKey = base64_encode($srcKey->encryptData($rawKey->key));
     $root = $this->encdoc->documentElement;
     $encKey = $this->encdoc->createElementNS(self::XMLENCNS, 'xenc:EncryptedKey');
     if ($append) {
         $keyInfo = $root->insertBefore($this->encdoc->createElementNS('http://www.w3.org/2000/09/xmldsig#', 'dsig:KeyInfo'), $root->firstChild);
         $keyInfo->appendChild($encKey);
     } else {
         $this->encKey = $encKey;
     }
     $encMethod = $encKey->appendChild($this->encdoc->createElementNS(self::XMLENCNS, 'xenc:EncryptionMethod'));
     $encMethod->setAttribute('Algorithm', $srcKey->getAlgorith());
     if (!empty($srcKey->name)) {
         $keyInfo = $encKey->appendChild($this->encdoc->createElementNS('http://www.w3.org/2000/09/xmldsig#', 'dsig:KeyInfo'));
         $keyInfo->appendChild($this->encdoc->createElementNS('http://www.w3.org/2000/09/xmldsig#', 'dsig:KeyName', $srcKey->name));
     }
     $cipherData = $encKey->appendChild($this->encdoc->createElementNS(self::XMLENCNS, 'xenc:CipherData'));
     $cipherData->appendChild($this->encdoc->createElementNS(self::XMLENCNS, 'xenc:CipherValue', $strEncKey));
     if (is_array($this->references) && count($this->references) > 0) {
         $refList = $encKey->appendChild($this->encdoc->createElementNS(self::XMLENCNS, 'xenc:ReferenceList'));
         foreach ($this->references as $name => $reference) {
             $refuri = $reference["refuri"];
             $dataRef = $refList->appendChild($this->encdoc->createElementNS(self::XMLENCNS, 'xenc:DataReference'));
             $dataRef->setAttribute("URI", '#' . $refuri);
         }
     }
     return;
 }
All Usage Examples Of RobRichards\XMLSecLibs\XMLSecurityKey::encryptData