Checagem de assinatura
Enviado: 20 Jun 2016 22:03
Achei isto no site da Microsoft, mas ainda em fase de conversão.
Não vai ser muito diferente no Harbour, porque usa classes do XML 5.0
É pra validar a assinatura do XML.
Durante conversão pra Harbour, fui confirmar aqueles componentes iniciais, aonde eram usados no fonte e.... não encontrei.
Fui no VB, e acrescentei no fonte: "Option Explicit", algo como a checagem -w3 -es2 que existe no Harbour.
E não é que deu erro nas linhas, porque não usa pra bost. nenhuma.
Belo exemplo de colocar lixo em fonte.... rs
Não vai ser muito diferente no Harbour, porque usa classes do XML 5.0
É pra validar a assinatura do XML.
Código: Selecionar todos
Dim xmldoc As New DOMDocument50
Dim xmldsig As New MXDigitalSignature50
Dim dsigKey As IXMLDSigKey
Dim dataObj As IXMLDOMNode
Const DSIGNS = "xmlns:ds='http://www.w3.org/2000/09/xmldsig#'"
Const INFILE = "signature.verify.dsa.xml"
Private Function WriteLine(ByVal str As String)
Text1.Text = Text1.Text + str + vbNewLine
End Function
Private Function writeClear()
Text1.Text = ""
End Function
Private Function LoadXML(ByVal file As String)
' Read input xml file and display the content in the text1.
Path = App.Path + "\" + file
xmldoc.async = False
xmldoc.preserveWhiteSpace = True
xmldoc.validateOnParse = False
xmldoc.resolveExternals = False
If xmldoc.Load(Path) = False Then
WriteLine "Can't load " + Path
WriteLine "Reason: " + xmldoc.parseError.reason
LoadXML = False
Exit Function
End If
xmldoc.setProperty "SelectionNamespaces", DSIGNS
Set xmldsig.signature = xmldoc.selectSingleNode(".//ds:Signature")
LoadXML = True
End Function
Private Function VerifyXML()
If xmldsig.signature Is Nothing Then
WriteLine "Invalid signature."
VerifyXML = False
Exit Function
End If
Set oKeyInfo = xmldoc.selectSingleNode(".//ds:KeyInfo/ds:KeyValue")
If oKeyInfo Is Nothing Then
WriteLine "Invalid <KeyInfo> element."
VerifyXML = False
Exit Function
End If
Set oPubKey = xmldsig.createKeyFromNode(oKeyInfo)
If oPubKey Is Nothing Then
WriteLine "Can't generate public key for verification."
VerifyXML = False
Exit Function
End If
Set oVerifiedKey = xmldsig.verify(oPubKey)
If oVerifiedKey Is Nothing Then
WriteLine "Signature not verified."
End If
WriteLine "Signature verified."
VerifyXML = True
End Function
Private Sub Form_Load()
writeClear
WriteLine "Verifyin signature."
If LoadXML(INFILE) = True Then
VerifyXML
End If
End Sub
Fui no VB, e acrescentei no fonte: "Option Explicit", algo como a checagem -w3 -es2 que existe no Harbour.
E não é que deu erro nas linhas, porque não usa pra bost. nenhuma.
Belo exemplo de colocar lixo em fonte.... rs