SAML2\Assertion::decryptNameId PHP Method

decryptNameId() public method

Decrypt the NameId of the subject in the assertion.
public decryptNameId ( XMLSecurityKey $key, array $blacklist = [] )
$key RobRichards\XMLSecLibs\XMLSecurityKey The decryption key.
$blacklist array Blacklisted decryption algorithms.
    public function decryptNameId(XMLSecurityKey $key, array $blacklist = array())
    {
        if ($this->encryptedNameId === null) {
            /* No NameID to decrypt. */
            return;
        }
        $nameId = Utils::decryptElement($this->encryptedNameId, $key, $blacklist);
        Utils::getContainer()->debugMessage($nameId, 'decrypt');
        $this->nameId = Utils::parseNameId($nameId);
        $this->encryptedNameId = null;
    }

Usage Example

 public function transform(Assertion $assertion)
 {
     if (!$assertion->isNameIdEncrypted()) {
         return $assertion;
     }
     $decryptionKeys = $this->privateKeyLoader->loadDecryptionKeys($this->identityProvider, $this->serviceProvider);
     $blacklistedKeys = $this->identityProvider->getBlacklistedAlgorithms();
     if (is_null($blacklistedKeys)) {
         $blacklistedKeys = $this->serviceProvider->getBlacklistedAlgorithms();
     }
     foreach ($decryptionKeys as $index => $key) {
         try {
             $assertion->decryptNameId($key, $blacklistedKeys);
             $this->logger->debug(sprintf('Decrypted assertion NameId with key "#%d"', $index));
         } catch (\Exception $e) {
             $this->logger->debug(sprintf('Decrypting assertion NameId with key "#%d" failed, "%s" thrown: "%s"', $index, get_class($e), $e->getMessage()));
         }
     }
     if ($assertion->isNameIdEncrypted()) {
         throw new NotDecryptedException('Could not decrypt the assertion NameId with the configured keys, see the debug log for information');
     }
     return $assertion;
 }
All Usage Examples Of SAML2\Assertion::decryptNameId