title: How to validate signature with phpseclib, in a XML signature message?
body: <p>I tested the final XML signature file and it sends, "invalid signatures", why?
  Information:
  I have prepared this inf. to be signed with XML signature:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;&lt;SolicitudRegistro
      xmlns="http://www.cie.mx/SCG/Inilidad" IdMensaje="f2-8505d81914c"&gt;
  &lt;FechaEnvio&gt;2013-02-26T21:08:36&lt;/FechaEnvio&gt;
  &lt;Registrante EndPoint="https://200.34.175.46:443/InteropOPE
      /MensajeidadService"  Nombre="Instigua" NombreCorto="IMTA" URI="op.mx"&gt;
  &lt;DatosDeContacto AreaOficina="Informatica" 
      CorreoElect="req@tc.ia.mx" Nombre="Rafadina" Puesto="Subdirector nicaciones" &gt;
  &lt;Telefonos&gt;
  &lt;Telefono Extension=" " NumeroTelefonico="7773293644" /&gt;
  &lt;/Telefonos&gt;
  &lt;/DatosDeContacto&gt;
  &lt;CertificadoInstancia&gt;MIIFETCCA/mgAwIBAgIUMDAwMDAwMDAwMDAwMD CERTIFICATE 
      WITH SENDER'S PUBLIC KEY=&lt;/CertificadoInstancia&gt;
  &lt;/Registrante&gt;
  &lt;Reto&gt;
  &lt;CadenaCifrada&gt;Ln0BAsnwrNg6IzjW7hk2c/Nxx/x3LZ STRING ENCRYPTED 
      WITH PRIVATE KEY SO RECEIVER CAN AUTHENTICATE SOURCE WITH SENDER'S CERTIFICATE=
  &lt;/CadenaCifrada&gt;
  &lt;/Reto&gt;
  &lt;/SolicitudRegistro&gt;
  </code></pre>
  
  <p>So I stored all this in file results.xml, then I sign it with phpseclib functions, the code is:</p>
  
  <pre><code>&lt;?php
  require('xmlseclibs.php');
  if (file_exists('./firmas/sign-basic-test_mio.xml')) {
      unlink('./firmas/sign-basic-test_mio.xml');
  }
  $doc = new DOMDocument();
  $doc-&gt;load('./firmas/results.xml');
  $objDSig = new XMLSecurityDSig();
  $objDSig-&gt;setCanonicalMethod(XMLSecurityDSig::C14N);
  $objDSig-&gt;addReference($doc, XMLSecurityDSig::SHA1,
      array('http://www.w3.org/2000/09/xmldsig#enveloped-signature',
      array('http://www.w3.org/TR/1999/REC-xpath-19991116' =&gt;
      array("query" =&gt; "ancestor-or-self::*[local-
      name()='SolicitudRegistro']"))),array("force_uri"=&gt;true));
  $objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=&gt;'private'));
  /* load private key */
  $objKey-&gt;loadKey('i.pem', TRUE);
  $objDSig-&gt;sign($objKey);
  /* Add associated public key */
  $objDSig-&gt;add509Cert(file_get_contents('instancia_imta_ope.crt'));
  $objDSig-&gt;appendSignature($doc-&gt;documentElement);
  $doc-&gt;save('./firmas/sign-basic-test_mio.xml');
  $sign_output = file_get_contents('./firmas/sign-basic-test_mio.xml');
  $sign_output_def = file_get_contents('./firmas/sign-basic-test_mio.res');
  if ($sign_output != $sign_output_def) {
      echo "NOT THE SAME";
  }
  echo "DONE";
  ?&gt;
  </code></pre>
  
  <p>This gives a complete XML signature that looks like (truncated some encrypted text):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;SolicitudRegistro xmlns="http://www.cb.mx/SCG/Interlidad"
      IdMensaje="f2e140eb-2b09-44ab-8504-87b25d81914c"&gt;
  &lt;FechaEnvio&gt;2013-02-26T21:08:36&lt;/FechaEnvio&gt;
  &lt;Registrante EndPoint="https://200.34.175.46:443/InteropOPE.....
  &lt;DatosDeContacto AreaOficina="Informatica" CorreoElectronico.....
  &lt;Telefonos&gt;
  &lt;Telefono Extension=" " NumeroTelefonico="7773293644"/&gt;
  &lt;/Telefonos&gt;
  &lt;/DatosDeContacto&gt;
  &lt;CertificadoInstancia&gt;MIIFETCCA/mgAwIBAgIUMDAwMDY....=&lt;/CertificadoInstancia&gt;
  &lt;/Registrante&gt;
  &lt;Reto&gt;
  &lt;CadenaCifrada&gt;Ln0BAsnwrNg6IzjW7hk.....&lt;/CadenaCifrada&gt;
  &lt;/Reto&gt;
  &lt;ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"&gt;
    &lt;ds:SignedInfo&gt;&lt;ds:CanonicalizationMethod
      Algorithm="http://ww.org/TR/2001 /REC-xml-c14n-20010315"/&gt;
     &lt;ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/&gt;
     &lt;ds:Reference URI=""&gt;&lt;ds:Transforms&gt;&lt;ds:Transform Algorithm="http://www.
     w3.org/2000/09/xmldsig#enveloped-signature"/&gt;&lt;ds:Transform
     Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116"&gt;
    &lt;ds:XPath&gt;ancestor-or-self::*[local-name()='SolicitudRegistro']&lt;/ds:XPath&gt;
    &lt;/ds:Transform&gt;&lt;/ds:Transforms&gt;&lt;ds:DigestMethod
    Algorithm="http://www.w3.org/2000/09 /xmldsig#sha1"
    /&gt;&lt;ds:DigestValue&gt;GogFeLcUThvfAeyNrDBroTQaGhA=&lt;/ds:DigestValue&gt;
   &lt;/ds:Reference&gt;
   &lt;/ds:SignedInfo&gt;&lt;ds:SignatureValue&gt;N+Btck0X9H81ZUcmrIK3h7LR2CtA86BPaBFE=
  &lt;/ds:SignatureValue&gt;
  &lt;ds:KeyInfo&gt;
  &lt;ds:X509Data&gt;
  &lt;ds:X509Certificate&gt;MIIFETCCA/mgAwIB.....=&lt;/ds:X509Certificate&gt;
  &lt;/ds:X509Data&gt;
  &lt;/ds:KeyInfo&gt;
  </code></pre>
  
  <p>
     </p>
  
  <p>All this for 1 question,
  do you know any example how to validate this signature using PHPSECLIB?
  Or another library?
  the testing page that shows invalid signatures is:
  <a href="https://ope.gob.mx/BrokerInteropQA/Diagnostico/default.aspx" rel="nofollow">https://ope.gob.mx/BrokerInteropQA/Diagnostico/default.aspx</a></p>
  
  <p>thanks, 
  I apologize for so much information, but I tried to be clear in my doubt
  mario</p>