Sample code for 30+ languages & platforms
AutoIt

Find Certificate by Subject OU (Organizational Unit)

See more Cert Store Examples

Demonstrates how to find a certificate having the specified subject organizational unit (OU).

Note: Requires Chilkat v10.1.2 or later.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

$oCertStore = ObjCreate("Chilkat.CertStore")

; This opens the Current User certificate store on Windows,
; On MacOS and iOS it opens the default Keychain.
Local $bReadOnly = False
$bSuccess = $oCertStore.OpenCurrentUserStore($bReadOnly)
If ($bSuccess = False) Then
    ConsoleWrite($oCertStore.LastErrorText & @CRLF)
    Exit
EndIf

; Find the certificate having a Subject OU = "Secretaria da Receita Federal do Brasil - RFB".
$oJson = ObjCreate("Chilkat.JsonObject")
Local $sOu = "Secretaria da Receita Federal do Brasil - RFB"
$oJson.UpdateString("OU",$sOu)

$oCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oCertStore.FindCert($oJson,$oCert)
If ($bSuccess = True) Then
    ; Show the full distinguished name of the certificate.
    ConsoleWrite("Found: " & $oCert.SubjectDN & @CRLF)
Else
    ConsoleWrite("Not found." & @CRLF)
EndIf