title: C# UBL 2.1 signature
body: <p>I need to sign an UBL 2.1 Invoice using c#.
  The proble is that, after signing i need the <code>Signature xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"</code> to be embeded in</p>
  
  <p>an UBLExtensions element, like so</p>
  
  <pre><code>&lt;Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"&gt;
  </code></pre>
  
  <p>
      
        
          
            
              </p>
  
  <p>I have tried to add these elements at a later time, but the signature is not considered valid.</p>
  
  <p>I don't have any experience signing XML files, so any help would be much apreciated</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The initial XML file is</p>
  
  <pre><code>&lt;Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"&gt;
     ... Invoice Elements
  &lt;/Invoice&gt;
  </code></pre>
  
  <p>I need to produce something like</p>
  
  <pre><code>&lt;Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"&gt;
     &lt;ext:UBLExtensions&gt;
        &lt;ext:UBLExtension xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2" xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2" xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2"&gt;
           &lt;ext:ExtensionContent&gt;
              &lt;sig:UBLDocumentSignatures&gt;
                 &lt;sac:SignatureInformation&gt;
                    &lt;Signature xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;
                       ... signature contents produced by signed xml class
                    &lt;/Signature&gt;
                 &lt;/sac:SignatureInformation&gt;
              &lt;/sig:UBLDocumentSignatures&gt;
           &lt;/ext:ExtensionContent&gt;
        &lt;/ext:UBLExtension&gt;
     &lt;/ext:UBLExtensions&gt;
      ... Invoice Elements
  &lt;/Invoice&gt;
  </code></pre>
  
  <p>If I add these elements at a later time, the signature is considered invalid.</p>
  
  <p>Again, any help will be highly appreciated.</p>
  
  <p>The link to the actual signed file is this one:
  <a href="https://drive.google.com/open?id=1dwDyLfpvRYN59T5Thkldu6t1ErMVtQ16" rel="nofollow noreferrer">signed_xml</a></p>