Hello everyone,
recently we are working on web services that use digitally signed xml files for validation, these xml files must be signed with digital certificates (.P12 files), does anyone have experience doing this? Or can you guide us how to do this in Pvx Plus? Any idea is welcome, thank you very much in advance.
Below is some example code in VB.NET. Any idea how we can replicate it in pxplus?
recently we are working on web services that use digitally signed xml files for validation, these xml files must be signed with digital certificates (.P12 files), does anyone have experience doing this? Or can you guide us how to do this in Pvx Plus? Any idea is welcome, thank you very much in advance.
Below is some example code in VB.NET. Any idea how we can replicate it in pxplus?
Code Select
''' <summary>
''' Method for signing XML with digital certificate (*.p12)
''' </summary>
''' <param name="xmlDoc"> document to sign </param>
''' <param name="pathCert">location of certificate to use for signing </param>
''' <param name="passCert">digital certificate password</param>
''' <returns>Digitally signed XML</returns>
Private Function Signed (ByVal xmlDoc As XmlDocument, ByVal pathCert As String, ByVal
passCert As String) As XmlDocument
Try
If Not File.Exists(pathCert) Then Throw New Exception("The signing certificate does not exist")
Dim cert = New X509Certificate2(pathCert, passCert, X509KeyStorageFlags.Exportable)
Dim exportedKeyMaterial = cert.PrivateKey.ToXmlString(True)
Dim key = New RSACryptoServiceProvider(New CspParameters(24))
key.PersistKeyInCsp = False
key.FromXmlString(exportedKeyMaterial)
Dim signedXml As SignedXml = New SignedXml(xmlDoc)
signedXml.SigningKey = key
signedXml.SignedInfo.SignatureMethod =
"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
Dim reference As Reference = New Reference()
reference.AddTransform(New XmlDsigEnvelopedSignatureTransform())
reference.DigestMethod = "http://www.w3.org/2001/04/xmlenc#sha256"
reference.Uri = ""
signedXml.AddReference(reference)
Dim keyInfo As KeyInfo = New KeyInfo()
keyInfo.AddClause(New KeyInfoX509Data(cert))
signedXml.KeyInfo = keyInfo
signedXml.ComputeSignature()
Dim xmlDigitalSignature As XmlElement = signedXml.GetXml()
xmlDoc.DocumentElement.AppendChild(xmlDoc.ImportNode(xmlDigitalSignature, True))
Return xmlDoc
Catch ex As Exception
Throw ex
End Try
End Function