Skip to content

Error Compute Signature VB2022 #341

Description

@aldodomingo2610

VB.net 2022:

I try to sign an XML but with an URI = Id whose value is numerical.
But "compute Signature" will not sign and generates an error:
System.Security.Cryptography.CryptographicException: Malformed reference element.
Certificado = New X509Certificate2(_CertArchivo, _CertContrasenia, X509KeyStorageFlags.Exportable)

  xdTmp = New XmlDocument With {

.PreserveWhitespace = False
}

  xdTmp.Load(xmlAFirmar)

sxTmp = New SignedXml(xdTmp) With {
.SigningKey = Certificado.GetRSAPrivateKey
}
sxTmp.SignedInfo.SignatureMethod = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
sxTmp.SignedInfo.CanonicalizationMethod = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"

    Dim ReferenceId As String = FindReferenceId(xdTmp)........'Call Function ReferenceID'
  
  refTmp = New Reference With {
         .Uri = "#" & ReferenceId
  }
 
  refTmp.AddTransform(New XmlDsigEnvelopedSignatureTransform)

refTmp.AddTransform(New XmlDsigC14NWithCommentsTransform)

sxTmp.AddReference(refTmp)

  sxTmp.ComputeSignature()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions