如何使用客户端证书认证在iOS应用 [英] How to use Client Certificate Authentication in iOS App

查看:125
本文介绍了如何使用客户端证书认证在iOS应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有对客户端证书认证了很多经验。任何人都可以告诉我如何使用它在iOS应用?感谢:)

I don't have a lot experience about Client Certificate Authentication. Anybody can tell me how to use it in iOS app? Thanks :)

推荐答案

您的 NSURLConnection的的代表应到连接回应:didReceiveAuthenticationChallenge:委托方法(见下面的链接)。

Your NSURLConnection delegate should respond to the connection:didReceiveAuthenticationChallenge: delegate method (see link below).

<一个href=\"http://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSURLConnection_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/connection:didReceiveAuthenticationChallenge\" rel=\"nofollow\">http://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSURLConnection_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/connection:didReceiveAuthenticationChallenge:

应该通过询问挑战它的发件人,并为其提供适当的凭据回应。

It should respond by asking the challenge for its 'sender' and providing it with an appropriate credential.

是这样的:

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
  id sender = [challenge sender];

  // create a credential from a certificate
  // see doco for details of the parameters
  NSURLCredential *creds = [NSURLCredential credentialWithIdentity:ident certificates:certs persistence:persistence];

  [sender useCredential:creds forAuthenticationChallenge:challenge];
}

见的 NSURLCredential 的有关如何基于证书创建凭据的详细信息类引用:

See the NSURLCredential class reference for details of how to create a credential based on a certificate:

这篇关于如何使用客户端证书认证在iOS应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆