Sample code for 30+ languages & platforms
Perl Requires Chilkat v10.1.2+

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).

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

my $certStore = Chilkat2::CertStore->new;

# This opens the Current User certificate store on Windows,
# On MacOS and iOS it opens the default Keychain.
my $readOnly = 0;
my $success = $certStore->OpenCurrentUserStore($readOnly);
if (!$success) {
    print $certStore->LastErrorText, "\n";
    exit;
}

# Find the certificate having a Subject OU = "Secretaria da Receita Federal do Brasil - RFB".
my $json = Chilkat2::JsonObject->new;
my $ou = 'Secretaria da Receita Federal do Brasil - RFB';
$json->UpdateString('OU', $ou);

my $cert = Chilkat2::Cert->new;
$success = $certStore->FindCert($json, $cert);
if ($success) {
    # Show the full distinguished name of the certificate.
    print 'Found: ', $cert->SubjectDN, "\n";
} else {
    print "Not found.\n";
}