Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. Public Function GetCertificado() As X509Certificate2
  2. Dim store As X509Store = New X509Store
  3. store.Open((OpenFlags.ReadOnly Or OpenFlags.OpenExistingOnly))
  4. Dim collection As X509Certificate2Collection = CType(store.Certificates, X509Certificate2Collection)
  5. Dim fcollection As X509Certificate2Collection = CType(collection.Find(X509FindType.FindByTimeValid, DateTime.Now, False), X509Certificate2Collection)
  6. Dim scollection As X509Certificate2Collection = X509Certificate2UI.SelectFromCollection(fcollection, "Certificados", "Seleccione un certificado", X509SelectionFlag.SingleSelection)
  7. If (scollection.Count = 0) Then
  8. Return Nothing
  9. End If
  10. Return scollection(0)
  11. End Function
  12.  
  13. Public Sub Sign(cert As X509Certificate2, route as String)
  14. Dim doc As XmlDocument = New XmlDocument()
  15. doc.LoadXml(File.ReadAllText(route))
  16.  
  17. Dim signedxml As SignedXml = New SignedXml(doc)
  18. Dim reference As Reference = New Reference()
  19. reference.Uri = ""
  20. Dim env As XmlDsigEnvelopedSignatureTransform = New XmlDsigEnvelopedSignatureTransform()
  21. reference.AddTransform(env)
  22. signedxml.AddReference(reference)
  23.  
  24. Dim KeyInfo As KeyInfo = New KeyInfo()
  25. KeyInfo.AddClause(New KeyInfoX509Data(cert))
  26. signedxml.KeyInfo = KeyInfo
  27. signedxml.SigningKeyName = cert.Subject
  28.  
  29. signedxml.SigningKey = cert.PrivateKey '<--- origen de error'
  30. signedxml.ComputeSignature()
  31. Dim xmlsig As XmlElement = signedxml.GetXml()
  32. doc.DocumentElement.AppendChild(doc.ImportNode(xmlsig, True))
  33. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement