How to verify a public key digital signature in iOS without using any third-party code (for example) to open SSL?
I need to verify the digital signature in an iOS public key application. Can anyone help me achieve this without using third-party software.
I am trying to make the code below, but the problem is that I do not have a certificate in my application, so I can not create SecTrustRef.
CODE:
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]
);
I have the following:
- Public Key (NSString *)
- Signature (NSString *)
- Data (NSString *)
Please help me that everything I have in the SDK for iOS, if I do not want to use ant third-party open source.
source
share