public static function insertSignature(
        XMLSecurityKey $key,
        array $certificates,
        DOMElement $root,
        DOMNode $insertBefore = null
    ) : void {
        $objXMLSecDSig = new XMLSecurityDSig();
        $objXMLSecDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);

        switch ($key->type) {
            case XMLSecurityKey::RSA_SHA256:
                $type = XMLSecurityDSig::SHA256;
                break;
            case XMLSecurityKey::RSA_SHA384:
                $type = XMLSecurityDSig::SHA384;
                break;
            case XMLSecurityKey::RSA_SHA512:
                $type = XMLSecurityDSig::SHA512;
                break;
            default:
                $type = XMLSecurityDSig::SHA1;
        }

        $objXMLSecDSig->addReferenceList(
            [$root],
            $type,
            ['http://www.w3.org/2000/09/xmldsig#enveloped-signature', XMLSecurityDSig::EXC_C14N],
            ['id_name' => 'ID', 'overwrite' => false]
        );

        $objXMLSecDSig->sign($key);

        foreach ($certificates as $certificate) {
            $objXMLSecDSig->add509Cert($certificate, true);
        }

        $objXMLSecDSig->insertSignature($root, $insertBefore);
    }
public static function insertSignature(
        XMLSecurityKey $key,
        array $certificates,
        DOMElement $root,
        DOMNode $insertBefore = null
    ) : void {
        $objXMLSecDSig = new XMLSecurityDSig();
        $objXMLSecDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);

        switch ($key->type) {
            case XMLSecurityKey::RSA_SHA256:
                $type = XMLSecurityDSig::SHA256;
                break;
            case XMLSecurityKey::RSA_SHA384:
                $type = XMLSecurityDSig::SHA384;
                break;
            case XMLSecurityKey::RSA_SHA512:
                $type = XMLSecurityDSig::SHA512;
                break;
            default:
                $type = XMLSecurityDSig::SHA1;
        }

        $objXMLSecDSig->addReferenceList(
            [$root],
            $type,
            ['http://www.w3.org/2000/09/xmldsig#enveloped-signature', XMLSecurityDSig::EXC_C14N],
            ['id_name' => 'ID', 'overwrite' => false]
        );

        $objXMLSecDSig->sign($key);

        foreach ($certificates as $certificate) {
            $objXMLSecDSig->add509Cert($certificate, true);
        }

        $objXMLSecDSig->insertSignature($root, $insertBefore);
    }
public static function insertSignature ( XMLSecurityKey $ key , array $ certificates , DOMElement $ root , DOMNode $ insertBefore = null ) : void { $ objXMLSecDSig = new XMLSecurityDSig ( ) ; $ objXMLSecDSig -> setCanonicalMethod ( XMLSecurityDSig :: EXC_C14N ) ; switch ( $ key -> type ) { case XMLSecurityKey :: RSA_SHA256 : $ type = XMLSecurityDSig :: SHA256 ; break ; case XMLSecurityKey :: RSA_SHA384 : $ type = XMLSecurityDSig :: SHA384 ; break ; case XMLSecurityKey :: RSA_SHA512 : $ type = XMLSecurityDSig :: SHA512 ; break ; default : $ type = XMLSecurityDSig :: SHA1 ; } $ objXMLSecDSig -> addReferenceList ( [ $ root ] , $ type , [ 'http://www.w3.org/2000/09/xmldsig#enveloped-signature' , XMLSecurityDSig :: EXC_C14N ] , [ 'id_name' => 'ID' , 'overwrite' => false ] ) ; $ objXMLSecDSig -> sign ( $ key ) ; foreach ( $ certificates as $ certificate ) { $ objXMLSecDSig -> add509Cert ( $ certificate , true ) ; } $ objXMLSecDSig -> insertSignature ( $ root , $ insertBefore ) ; }
Insert a Signature node.

@param XMLSecurityKey $key The key we should use to sign the message.
@param array $certificates The certificates we should add to the signature node.
@param \DOMElement $root The XML node we should sign.
@param \DOMNode $insertBefore  The XML element we should insert the signature element before.
@return void
Insert a Signature node .