I read cert info by use
NSString *summary = CFBridgingRelease(SecCertificateCopySubjectSummary(cert));
which get the cert summary, when the summary is chinese, such as 中,the summary return as ä¸
how can i encode ä¸ to 中 correct?
The code how i get cert summary
CFMutableDictionaryRef query = CFDictionaryCreateMutable(nil, 4, nil, nil);
CFDictionaryAddValue(query, kSecClass, kSecClassCertificate);
CFDictionaryAddValue(query, kSecMatchLimit, (const void *)@(100));
CFDictionaryAddValue(query, kSecReturnRef, kCFBooleanTrue);
CFArrayRef items;
OSStatus status = SecItemCopyMatching(query, (CFTypeRef *)&items);
NSArray *certificates = CFBridgingRelease(items);
for (int i = 0; i < certificates.count; i++)
{
SecCertificateRef certificate = (__bridge SecCertificateRef)certificates[i];
NSString *summary = (NSString *)CFBridgingRelease(SecCertificateCopySubjectSummary(certificate);
NSLog(@"%@", summary);
}
when summary is a chinese string, the result is not right.
SecCertificateCopySubjectSummary()line, which makes me wonder how this differs from your real code. Anyway, it may be that this is just a bug inSecCertificateCopySubjectSummary(). AnNSStringorCFStringis intended to be encoding-neutral. Or, another way to think about it, it should be already decoded into an internal representation. The API is in terms of "characters", by which it actually means UTF-16 code units, but the internal representation could be anything. It should not be possible to get an encoding mistake like this.