如何在不使用任何第三方代码(例如)开放 SSL 的情况下在 iOS 中使用公钥验证数字签名?
我需要使用公钥验证 iOS App 中的数字签名。有人可以帮助我如何在不使用第三方软件的情况下实现这一目标。
我正在尝试以下代码,但问题是我的应用程序中没有证书,因此无法创建SecTrustRef。
代码:
NSString *certPath = [[NSBundle mainBundle] pathForResource:@"yyy"
ofType:@"xxx"];
SecCertificateRef myCertificate = nil;
NSData *certificateData = [[NSData alloc] initWithContentsOfFile :certPath];
myCertificate = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)certificateData);
SecPolicyRef myPolicy = SecPolicyCreateBasicX509();
SecTrustRef trustRef;
SecTrustCreateWithCertificates(myCertificate, myPolicy, &trustRef);
SecKeyRef keyRef = SecTrustCopyPublicKey (trustRef);
BOOL status = SecKeyRawVerify (keyRef,
kSecPaddingPKCS1SHA1,
(const uint8_t *)[data bytes],
(size_t)[data length],
(const uint8_t *)[signature bytes],
(size_t)[signature length]
);
我有以下内容:
- 公钥(NSString*)
- 签名(NSString*)
- 数据(NSString*)
如果我不想使用 ant 第三方开源,请帮助我在 iOS SDK 中的所有选项。