Re: Como saber si un certificado es FIEL o es de Sellos?
Publicado: Sab Feb 05, 2011 11:43 am
Hola,
Aqui 2 functiones en VB.net usando el chilkatDotNet2.dll :
Public Function keysMatch() As Boolean
Dim cer As New Chilkat.Cert
Dim privateKey As New Chilkat.PrivateKey
Dim xml As New Chilkat.Xml
Try
Dim cerXmlFile As String = tmpPath & "cer.xml"
Dim keyXmlFile As String = tmpPath & "key.xml"
If cer.LoadFromFile(cerFile) = False Then Throw New Exception(cer.LastErrorText) 'load cer
If cer.ExportPublicKey().SaveXmlFile(cerXmlFile) = False Then Throw New Exception(cer.LastErrorText) 'save as xml
If xml.LoadXmlFile(cerXmlFile) = False Then Throw New Exception(xml.LastErrorText) 'load cerXml
Dim modulusCer = xml.GetRoot.GetChildContent("Modulus") : deleteFile(cerXmlFile) 'get modulusCer
If privateKey.LoadPkcs8EncryptedFile(keyFile, pwd) = False Then Throw New Exception(privateKey.LastErrorText) 'load key
If privateKey.SaveXmlFile(keyXmlFile) = False Then Throw New Exception(privateKey.LastErrorText) 'save as xml
If xml.LoadXmlFile(keyXmlFile) = False Then Throw New Exception(xml.LastErrorText) 'load keyXml
Dim modulusKey = xml.GetRoot.GetChildContent("Modulus") : deleteFile(keyXmlFile) 'get modulusKey
If modulusCer = modulusKey Then Return True Else Return False
Catch ex As Exception
errHandler(ex)
Return False
Finally
If cer IsNot Nothing Then cer.Dispose()
If privateKey IsNot Nothing Then privateKey.Dispose()
If xml IsNot Nothing Then xml.Dispose()
End Try
End Function
Public Function cerIs4Sellos() As Boolean
Dim cer As New Chilkat.Cert
Try
If cer.LoadFromFile(cerFile) = False Then Throw New Exception(cer.LastErrorText) 'load cer
If cer.IntendedKeyUsage = 192 Then Return True Else Return False 'SELLOS = 192, FIEL = ?
Catch ex As Exception
errHandler(ex)
Return False
Finally
If cer IsNot Nothing Then cer.Dispose()
End Try
Return True
End Function
Aqui 2 functiones en VB.net usando el chilkatDotNet2.dll :
Public Function keysMatch() As Boolean
Dim cer As New Chilkat.Cert
Dim privateKey As New Chilkat.PrivateKey
Dim xml As New Chilkat.Xml
Try
Dim cerXmlFile As String = tmpPath & "cer.xml"
Dim keyXmlFile As String = tmpPath & "key.xml"
If cer.LoadFromFile(cerFile) = False Then Throw New Exception(cer.LastErrorText) 'load cer
If cer.ExportPublicKey().SaveXmlFile(cerXmlFile) = False Then Throw New Exception(cer.LastErrorText) 'save as xml
If xml.LoadXmlFile(cerXmlFile) = False Then Throw New Exception(xml.LastErrorText) 'load cerXml
Dim modulusCer = xml.GetRoot.GetChildContent("Modulus") : deleteFile(cerXmlFile) 'get modulusCer
If privateKey.LoadPkcs8EncryptedFile(keyFile, pwd) = False Then Throw New Exception(privateKey.LastErrorText) 'load key
If privateKey.SaveXmlFile(keyXmlFile) = False Then Throw New Exception(privateKey.LastErrorText) 'save as xml
If xml.LoadXmlFile(keyXmlFile) = False Then Throw New Exception(xml.LastErrorText) 'load keyXml
Dim modulusKey = xml.GetRoot.GetChildContent("Modulus") : deleteFile(keyXmlFile) 'get modulusKey
If modulusCer = modulusKey Then Return True Else Return False
Catch ex As Exception
errHandler(ex)
Return False
Finally
If cer IsNot Nothing Then cer.Dispose()
If privateKey IsNot Nothing Then privateKey.Dispose()
If xml IsNot Nothing Then xml.Dispose()
End Try
End Function
Public Function cerIs4Sellos() As Boolean
Dim cer As New Chilkat.Cert
Try
If cer.LoadFromFile(cerFile) = False Then Throw New Exception(cer.LastErrorText) 'load cer
If cer.IntendedKeyUsage = 192 Then Return True Else Return False 'SELLOS = 192, FIEL = ?
Catch ex As Exception
errHandler(ex)
Return False
Finally
If cer IsNot Nothing Then cer.Dispose()
End Try
Return True
End Function