对于那些对我的方法感兴趣的人,我会在这里留下我的片段。干杯!
#import <Foundation/Foundation.h>
id getX509ValueforKey(SecCertificateRef certificate, CFStringRef kSecPropertyKey) {
id value;
CFDictionaryRef valuesDict = SecCertificateCopyValues(certificate, (__bridge CFArrayRef)@[(__bridge id)kSecPropertyKey], NULL);
if (valuesDict) {
CFDictionaryRef invalidityDateDictionaryRef = CFDictionaryGetValue(valuesDict, kSecPropertyKey);
if (invalidityDateDictionaryRef) {
CFTypeRef invalidityRef = CFDictionaryGetValue(invalidityDateDictionaryRef, kSecPropertyKeyValue);
if (invalidityRef)
value = CFBridgingRelease(invalidityRef);
}
CFRelease(valuesDict);
}
return value;
}
int main(int argc, const char * argv[]) {
SecCertificateRef certificateRef = NULL;
NSDate *certExpiryDate = getX509ValueforKey(certificateRef, kSecOIDInvalidityDate);
NSLog(@"certExpiryDate: %@", certExpiryDate);
return noErr;
}