Skip to content

Instantly share code, notes, and snippets.

@pedroinfo
Last active February 27, 2025 10:38
Show Gist options
  • Save pedroinfo/a79043c4c9525d6e2e6f9a1d0f79a948 to your computer and use it in GitHub Desktop.
Save pedroinfo/a79043c4c9525d6e2e6f9a1d0f79a948 to your computer and use it in GitHub Desktop.
Function IsSmartCardCertificate(pCertContext As LongPtr) As Boolean
Dim cbData As Long
Dim provInfo As String
Dim isSmartCard As Boolean
' Obtém o tamanho das informações do provedor de chaves
If CertGetCertificateContextProperty(pCertContext, CERT_KEY_PROV_INFO_PROP_ID, 0, cbData) = 0 Then
IsSmartCardCertificate = False
Exit Function
End If
' Aloca memória para as informações do provedor de chaves
provInfo = String(cbData, 0)
' Obtém as informações do provedor de chaves
If CertGetCertificateContextProperty(pCertContext, CERT_KEY_PROV_INFO_PROP_ID, StrPtr(provInfo), cbData) = 0 Then
IsSmartCardCertificate = False
Exit Function
End If
' Exibe as informações do provedor de chaves para depuração
Debug.Print "Informações do Provedor de Chaves: " & provInfo
' Verifica se o provedor de chaves contém "Smart Card"
If InStr(1, provInfo, "Smart Card", vbTextCompare) > 0 Then
isSmartCard = True
Else
isSmartCard = False
End If
' Retorna o resultado
IsSmartCardCertificate = isSmartCard
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment