SignedXml : Problème avec ComputeSignature
Bonjour à tous,
Tout d’abord, j’ai jeté un oeil au tutoriel ici :
http://stormimon.developpez.com/dotn...tronique/#L2.4
Je semble procéder tel qu’indiqué dans le tutoriel, mais j’obtiens toujours le message d’erreur suivant lorsque la méthode ComputeSignature de la classe SignedXml est appelée :
Citation:
“Could not create hash algorithm object”.
Voic le code que j’utilise (considérer que la méthode LocateCertificate retourne le bon certificat) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
Dim doc As System.Xml.XmlDocument = New System.Xml.XmlDocument
doc.LoadXml(TestSerialisation.xdSerialization.Serialize(retval))
Dim signedXml As SignedXml = New SignedXml(doc)
'Ici le certificat retourné est le bon
Dim cert As X509Certificate2 = LocateCertificate()
signedXml.SigningKey = cert.PrivateKey
signedXml.SignedInfo.CanonicalizationMethod = signedXml.XmlDsigC14NTransformUrl
signedXml.SignedInfo.SignatureMethod = signedXml.XmlDsigRSASHA1Url
Dim reference As Reference = New Reference("#_0")
reference.DigestMethod = signedXml.XmlDsigRSASHA1Url
Dim transform As XmlDsigExcC14NTransform = New Security.Cryptography.Xml.XmlDsigExcC14NTransform
reference.AddTransform(transform)
signedXml.AddReference(reference)
Dim keyinfo As KeyInfo = New KeyInfo()
Dim kData As KeyInfoX509Data = New KeyInfoX509Data(cert, X509IncludeOption.EndCertOnly)
kData.AddSubjectName(cert.Subject)
keyinfo.AddClause(kData)
signedXml.KeyInfo = keyinfo
signedXml.ComputeSignature()
Dim xmlDigitalSignature As System.Xml.XmlElement = signedXml.GetXml
'... |
Merci d'avance de l'aide que vous pourrez m'apporter!