You are here

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

Encrypt the NameID in the Assertion.

Parameters

XMLSecurityKey $key The encryption key.:

File

includes/Assertion.php, line 518

Class

SAML2_Assertion

Code

public function encryptNameId(XMLSecurityKey $key) {

  /* First create a XML representation of the NameID. */
  $doc = new DOMDocument();
  $root = $doc
    ->createElement('root');
  $doc
    ->appendChild($root);
  Utilities::addNameId($root, $this->nameId);
  $nameId = $root->firstChild;
  Utilities::getContainer()
    ->debugMessage($nameId, 'encrypt');

  /* Encrypt the NameID. */
  $enc = new XMLSecEnc();
  $enc
    ->setNode($nameId);

  // @codingStandardsIgnoreStart
  $enc->type = XMLSecEnc::Element;

  // @codingStandardsIgnoreEnd
  $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
  $symmetricKey
    ->generateSessionKey();
  $enc
    ->encryptKey($key, $symmetricKey);
  $this->encryptedNameId = $enc
    ->encryptNode($symmetricKey);
  $this->nameId = NULL;
}