title: Verify digital signature with public key in iOS
body: <p><strong>How to Verify digital signature with public key in iOS without using any third party code(e.g.) open SSL?</strong></p>
  
  <p>I need to verify Digital signature in iOS App with a public key. Can some one help me how to achieve that without using third party software.</p>
  
  <p>I am trying below code but the problem is I don't have certificate in my App so can not create <em>SecTrustRef</em>.</p>
  
  <p>CODE:</p>
  
  <pre><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, &amp;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]
                                );
  </code></pre>
  
  <p>I have the following:</p>
  
  <ul>
  <li>Public Key (NSString*)</li>
  <li>Signature (NSString*)</li>
  <li>Data (NSString*)</li>
  </ul>
  
  <p>Please help me what all option I have in iOS SDK if I don't want to use ant third party open source.</p>