Certificate Management
The advantage of the Aloaha CSP APIs is that the user does not need to know in which connected card reader the card is located. Aloaha uses several algorythm to find the right reader.
Functions
The function get_certificate_by_reader returns the certificate of a card inserted in a known card reader.
function get_certificate_by_reader(ByVal LngReader As Long, ByRef CertificateBA As Variant, ByRef CA_BA As Variant, ByVal ctype As CertificateType) as boolean
For example
Dim LngReader as long
Dim CertificateBA() as byte
Dim CA_BA() as byte
Dim ctype as long
Dim CertificateString as String
ctype = 0 ' read non repudiation certificate
LngReader = 0 ' use first connected card reader
if ACSP.get_certificate_by_reader(LngReader,CertificateBA, CA_BA,ctype)=true then
'msgbox ACSP.BA2STR(CertificateBA)
call ACSP.Display_Certificate(CertificateBA)
end if
The function FindCertificate searches all connected card reader for a specific certificate.
Function FindCertificate(ByVal SearchString As String, ByVal SearchFilter As SearchFilter, ByVal ctype As CertificateType, ByRef fingerprint As String, ByRef CertificateBA As Variant) As Long
Searchfilter can be of type:
- CertificateSubject = 0
Searches for a Certificate with the given Subject.
- CertificateSimpleSubject = 1
Searches for a Certificate with a given simple Subject.
- CertificateFingerprint = 2
Searches for a Certificate with the given fingerprint.
- CertificateIssuer = 3
Returns the first Certificate with the given Issuer.
- CertificateEmail = 4
Returns the first Certificate with the given email address.
- CertificateBSTR = 5
Finds the given Certificate.
- CertificateSerialNumber = 6
Returns the Certificate with the given Serial Number.
- FreeText = 7
Does a free text search for certificates.
- Dialog = 8
Will display a dialog with the list of certificates physically available.
The sample below will find the first non repudiation certificate which contains the String "Stefan Engelbert". It will return the card reader holding the card and the fingerprint of the certificate.
Const FreeText = 7
Const SignatureCertificate = 0
Dim ACSP As Object
Dim SearchString As String
Dim SearchFilter As Long
Dim FingerPrint As String
Dim CardReader As Long
SearchString = "Stefan Engelbert"
SearchFilter = FreeText
ctype = SignatureCertificate
Set ACSP = CreateObject("AloahaCSPCore.provider")
CardReader = ACSP.FindCertificate(SearchString, SearchFilter, ctype, FingerPrint, vbNull)
If CardReader > -1 Then
MsgBox "Found Certificate with Fingerprint: " + FingerPrint + " in Reader " + ACSP.ReaderName(CardReader)
End If
Set ASP = Nothing
Properties
FingerPrint_by_Reader returns the fingerprint of the certificate of the given card reader.
For example fingerprint = ACSP.FingerPrint_by_Reader(0,1) returns the fingerprint of the signature/authentication certificate of the first card reader.
Property publickeyBA retrieves the public key of a certificate. That can be required for public key encryption or manual signature validation.
Dim PublicKey() as byte
Dim PublicKeyString as strnig
Dim FingerPrint as string
Dim CType
Fingerprint = <Fingerprint of Certificate>
CType = Type of Certificate (0, 1 or 2)
PublicKey = ACSP.publickeyBA(Fingerprint, CType)
PublicKeyString=ACSP.BA2STR(PublicKey)
Aloaha Software / Knowledge Base / Smart Card API / Aloaha CSP API / Certificate Management