Error Signing XML, URI Invalid VB.NET

Asked

Viewed 500 times

2

I have this code to sign an XML, because right now it asks for a URI, I know it’s a namespace that points to some site, 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

Next step to URI: http://www.w3.org/2000/09/xmldsig# 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>

1 answer

1

The method also accepts a tag of the kind string, I think the easiest way to locate 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.