SignedXML with URI = ID (value number)

domingo

New member
Joined
Feb 27, 2025
Messages
1
Programming Experience
3-5
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 = "xmldsig-more namespace"
sxTmp.SignedInfo.CanonicalizationMethod = "Canonical XML"

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()
 
Last edited:
Back
Top