Error Signing XML, Invalid URI VB.NET

2

I have this code to sign an XML, because at that moment it requests a URI, I know it is a namespace that points to some website, but when I assign the URL, it gives an exception error.

' Cria a referencia
    Dim reference As New Reference()

' Pega a URI para ser assinada
    Dim _Uri As XmlAttributeCollection = docXML.GetElementsByTagName(uri).Item(0).Attributes

    For Each _atributo As XmlAttribute In _Uri
        If _atributo.Name = "id" Then
            reference.Uri = "#" + _atributo.InnerText
        End If
    Next

I pass the following URI: link And I use the following XML:

<?xml version="1.0"?>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
  <ds:SignedInfo>
   <ds:CanonicalizationMethod Algorithm="http://www.altova.com/"/>
    <ds:SignatureMethod Algorithm="http://www.altova.com/"/>
     <ds:Reference>
     <ds:Transforms>
       <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
       <ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
   </ds:Transforms>
 <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
  <ds:DigestValue/>
   </ds:Reference>
   </ds:SignedInfo>
  <ds:SignatureValue/>
 <ds:KeyInfo>
  <ds:X509Data>
   <ds:X509Certificate/>
  </ds:X509Data>
  </ds:KeyInfo>

    
asked by anonymous 01.04.2015 / 20:03

1 answer

1

The method also accepts a tag of type string , I think the easiest way to find uri to be signed ( Id ) is by name:

   Dim tagAss = "infNFe"
    Dim _Uri As XmlAttributeCollection = doc.GetElementsByTagName(tagAss).Item(0).Attributes
    For Each atributo As XmlAttribute In _Uri
        If atributo.Name = "Id" Then
            Referencia.Uri = "#" & atributo.InnerText
        End If
    Next
    
02.04.2015 / 16:46