Code Duplication    Length = 23-25 lines in 3 locations

src/SAML2/AuthnRequest.php 1 location

@@ 605-629 (lines=25) @@
602
     *
603
     * @param XMLSecurityKey $key The encryption key.
604
     */
605
    public function encryptNameId(XMLSecurityKey $key)
606
    {
607
        /* First create a XML representation of the NameID. */
608
        $doc  = new \DOMDocument();
609
        $root = $doc->createElement('root');
610
        $doc->appendChild($root);
611
        Utils::addNameId($root, $this->nameId);
612
        $nameId = $root->firstChild;
613
614
        Utils::getContainer()->debugMessage($nameId, 'encrypt');
615
616
        /* Encrypt the NameID. */
617
        $enc = new XMLSecEnc();
618
        $enc->setNode($nameId);
619
        // @codingStandardsIgnoreStart
620
        $enc->type = XMLSecEnc::Element;
621
        // @codingStandardsIgnoreEnd
622
623
        $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
624
        $symmetricKey->generateSessionKey();
625
        $enc->encryptKey($key, $symmetricKey);
626
627
        $this->encryptedNameId = $enc->encryptNode($symmetricKey);
628
        $this->nameId          = null;
629
    }
630
631
    /**
632
     * Decrypt the NameId of the subject in the assertion.

src/SAML2/LogoutRequest.php 1 location

@@ 126-148 (lines=23) @@
123
     *
124
     * @param XMLSecurityKey $key The encryption key.
125
     */
126
    public function encryptNameId(XMLSecurityKey $key)
127
    {
128
        /* First create a XML representation of the NameID. */
129
        $doc = DOMDocumentFactory::create();
130
        $root = $doc->createElement('root');
131
        $doc->appendChild($root);
132
        Utils::addNameId($root, $this->nameId);
133
        $nameId = $root->firstChild;
134
135
        Utils::getContainer()->debugMessage($nameId, 'encrypt');
136
137
        /* Encrypt the NameID. */
138
        $enc = new XMLSecEnc();
139
        $enc->setNode($nameId);
140
        $enc->type = XMLSecEnc::Element;
141
142
        $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
143
        $symmetricKey->generateSessionKey();
144
        $enc->encryptKey($key, $symmetricKey);
145
146
        $this->encryptedNameId = $enc->encryptNode($symmetricKey);
147
        $this->nameId = null;
148
    }
149
150
    /**
151
     * Decrypt the NameID in the LogoutRequest.

src/SAML2/Assertion.php 1 location

@@ 681-705 (lines=25) @@
678
     *
679
     * @param XMLSecurityKey $key The encryption key.
680
     */
681
    public function encryptNameId(XMLSecurityKey $key)
682
    {
683
        /* First create a XML representation of the NameID. */
684
        $doc = DOMDocumentFactory::create();
685
        $root = $doc->createElement('root');
686
        $doc->appendChild($root);
687
        Utils::addNameId($root, $this->nameId);
688
        $nameId = $root->firstChild;
689
690
        Utils::getContainer()->debugMessage($nameId, 'encrypt');
691
692
        /* Encrypt the NameID. */
693
        $enc = new XMLSecEnc();
694
        $enc->setNode($nameId);
695
        // @codingStandardsIgnoreStart
696
        $enc->type = XMLSecEnc::Element;
697
        // @codingStandardsIgnoreEnd
698
699
        $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
700
        $symmetricKey->generateSessionKey();
701
        $enc->encryptKey($key, $symmetricKey);
702
703
        $this->encryptedNameId = $enc->encryptNode($symmetricKey);
704
        $this->nameId = null;
705
    }
706
707
    /**
708
     * Decrypt the NameId of the subject in the assertion.