(Objective-C) Find Certificate by SHA1 Thumbprint
Demonstrates how to find a certificate having the specified hexadecimal SHA1 thumbprint.
Note: Requires Chilkat v10.1.2 or later.
#import <CkoCertStore.h>
#import <CkoJsonObject.h>
#import <NSString.h>
#import <CkoCert.h>
CkoCertStore *certStore = [[CkoCertStore alloc] init];
// This opens the Current User certificate store on Windows,
// On MacOS and iOS it opens the default Keychain.
BOOL readOnly = NO;
BOOL success = [certStore OpenCurrentUserStore: readOnly];
if (success == NO) {
NSLog(@"%@",certStore.LastErrorText);
return;
}
// Find the certificate having a specific SHA1 thumbprint.
CkoJsonObject *json = [[CkoJsonObject alloc] init];
NSString *hexThumbprint = @"767192374BE3C1512D2CB80734926D40E96D6DC2";
[json UpdateString: @"thumbprint" value: hexThumbprint];
CkoCert *cert = [[CkoCert alloc] init];
success = [certStore FindCert: json cert: cert];
if (success == YES) {
// Show the full distinguished name of the certificate.
NSLog(@"%@%@",@"Found: ",cert.SubjectDN);
}
else {
NSLog(@"%@",@"Not found.");
}
|