Skip to content

Error Compute Signature VB2022 #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aldodomingo2610 opened this issue Feb 27, 2025 · 0 comments
Open

Error Compute Signature VB2022 #341

aldodomingo2610 opened this issue Feb 27, 2025 · 0 comments

Comments

@aldodomingo2610
Copy link

aldodomingo2610 commented Feb 27, 2025

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant