源碼0603-10-掌握-MD5加密-11-掌握-HTTPS

來源:互聯網
上載者:User

標籤:伺服器   init   text   turn   利用   elf   conf   challenge   receive   

 

 

////  ViewController.m//  10-掌握-MD5加密#import "ViewController.h"#import "NSString+Hash.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];        // 使用者輸入的還是520it    // 加密:21bfcc4c2625469d8ec6f3d710dcb0fe    // 亂序:21bfcc4c2625469d8ec6f3d710dcb0fe        NSString *text = @"520it";    NSString *md = [text md5String];        NSLog(@"%@", md);}@end



////  ViewController.m//  11-掌握-HTTPS#import "ViewController.h"@interface ViewController () <NSURLSessionTaskDelegate>@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];        NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[[NSOperationQueue alloc] init]];        NSURLSessionDataTask *task = [session dataTaskWithURL:[NSURL URLWithString:@"https://www.apple.com/"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {        NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);    }];        [task resume];}#pragma mark - <NSURLSessionTaskDelegate>/** * challenge : 挑戰、質詢 * completionHandler : 通過調用這個block,來告訴URLSession要不要接收這個認證 */- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler{    // 如果不是伺服器信任類型的認證,直接返回    if (![challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) return;        // void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *)    // NSURLSessionAuthChallengeDisposition : 如何處理這個安全性憑證    // NSURLCredential :安全性憑證        // 根據伺服器的信任資訊建立認證對象//    NSURLCredential *crdential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];    // 利用這個block說明使用這個認證//    if (completionHandler) {//        completionHandler(NSURLSessionAuthChallengeUseCredential, crdential);//    }        !completionHandler ? : completionHandler(NSURLSessionAuthChallengeUseCredential, challenge.proposedCredential);}@end

 

源碼0603-10-掌握-MD5加密-11-掌握-HTTPS

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.