public function sign()
	{
		// the document must be set up
		if (is_null($this->doc))
		{
			return new \UnexpectedValueException('No document structure to sign');
		}
		
		// find the SignedInfo element, which is what we will actually sign
		$signedInfo = $this->doc->getElementsByTagName($this->nodeNsPrefix . 'SignedInfo')->item(0);		
		if (is_null($signedInfo))
		{
			throw new \UnexpectedValueException('Unabled to locate the SignedInfo node');
		}
		
		// canonicalize the SignedInfo element for signing
		$c14nSignedInfo = $this->canonicalize($signedInfo);

		// make sure that we know which OpenSSL algo type to use
		if (!array_key_exists($this->digestMethod, $this->openSSLAlgoMapping))
		{
			throw new \UnexpectedValueException('No OpenSSL algorithm has been defined for digest of type ' . $this->digestMethod);
		}
		
		// sign the SignedInfo element using the private key
		if (!openssl_sign($c14nSignedInfo, $signature, $this->privateKey, $this->openSSLAlgoMapping[$this->digestMethod]))
		{
			throw new \UnexpectedValueException('Unable to sign the document. Error: ' . openssl_error_string());
		}
		
		$signature = base64_encode($signature);
		
		// find the signature value node, to which we will append the base64 encoded signature
		$signatureNode = $this->doc->getElementsByTagName($this->nodeNsPrefix . 'SignatureValue')->item(0);		
		if (is_null($signatureNode))
		{
			throw new \UnexpectedValueException('Unabled to locate the SingatureValue node');
		}
		
		$signatureNode->appendChild($this->doc->createTextNode($signature));
		
		return true;
	}
public function sign()
	{
		// the document must be set up
		if (is_null($this->doc))
		{
			return new \UnexpectedValueException('No document structure to sign');
		}
		
		// find the SignedInfo element, which is what we will actually sign
		$signedInfo = $this->doc->getElementsByTagName($this->nodeNsPrefix . 'SignedInfo')->item(0);		
		if (is_null($signedInfo))
		{
			throw new \UnexpectedValueException('Unabled to locate the SignedInfo node');
		}
		
		// canonicalize the SignedInfo element for signing
		$c14nSignedInfo = $this->canonicalize($signedInfo);

		// make sure that we know which OpenSSL algo type to use
		if (!array_key_exists($this->digestMethod, $this->openSSLAlgoMapping))
		{
			throw new \UnexpectedValueException('No OpenSSL algorithm has been defined for digest of type ' . $this->digestMethod);
		}
		
		// sign the SignedInfo element using the private key
		if (!openssl_sign($c14nSignedInfo, $signature, $this->privateKey, $this->openSSLAlgoMapping[$this->digestMethod]))
		{
			throw new \UnexpectedValueException('Unable to sign the document. Error: ' . openssl_error_string());
		}
		
		$signature = base64_encode($signature);
		
		// find the signature value node, to which we will append the base64 encoded signature
		$signatureNode = $this->doc->getElementsByTagName($this->nodeNsPrefix . 'SignatureValue')->item(0);		
		if (is_null($signatureNode))
		{
			throw new \UnexpectedValueException('Unabled to locate the SingatureValue node');
		}
		
		$signatureNode->appendChild($this->doc->createTextNode($signature));
		
		return true;
	}
public function sign ( ) { // the document must be set up if ( is_null ( $ this -> doc ) ) { return new \ UnexpectedValueException ( 'No document structure to sign' ) ; } // find the SignedInfo element, which is what we will actually sign $ signedInfo = $ this -> doc -> getElementsByTagName ( $ this -> nodeNsPrefix . 'SignedInfo' ) -> item ( 0 ) ; if ( is_null ( $ signedInfo ) ) { throw new \ UnexpectedValueException ( 'Unabled to locate the SignedInfo node' ) ; } // canonicalize the SignedInfo element for signing $ c14nSignedInfo = $ this -> canonicalize ( $ signedInfo ) ; // make sure that we know which OpenSSL algo type to use if ( ! array_key_exists ( $ this -> digestMethod , $ this -> openSSLAlgoMapping ) ) { throw new \ UnexpectedValueException ( 'No OpenSSL algorithm has been defined for digest of type ' . $ this -> digestMethod ) ; } // sign the SignedInfo element using the private key if ( ! openssl_sign ( $ c14nSignedInfo , $ signature , $ this -> privateKey , $ this -> openSSLAlgoMapping [ $ this -> digestMethod ] ) ) { throw new \ UnexpectedValueException ( 'Unable to sign the document. Error: ' . openssl_error_string ( ) ) ; } $ signature = base64_encode ( $ signature ) ; // find the signature value node, to which we will append the base64 encoded signature $ signatureNode = $ this -> doc -> getElementsByTagName ( $ this -> nodeNsPrefix . 'SignatureValue' ) -> item ( 0 ) ; if ( is_null ( $ signatureNode ) ) { throw new \ UnexpectedValueException ( 'Unabled to locate the SingatureValue node' ) ; } $ signatureNode -> appendChild ( $ this -> doc -> createTextNode ( $ signature ) ) ; return true ; }
Signs the XML document with an XML digital signature

@throws	\UnexpectedValueException	If the XML tree is not intact or if there is no OpenSSL mapping set
@return	bool						True if the document was successfully signed, false otherwise
Signs the XML document with an XML digital signature