zoukankan      html  css  js  c++  java
  • 源码0603-10-掌握-MD5加密-11-掌握-HTTPS

    //
    //  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
    本人无商业用途,仅仅是学习做个笔记,特别鸣谢小马哥,学习了IOS,另日语学习内容有需要文本和音频请关注公众号:riyuxuexishuji
  • 相关阅读:
    js判断选择时间不能小于当前时间的代码
    shell脚本编程之for语句、if语句使用介绍
    linux命令 chattr超级权限控件
    教你配置linux服务器登陆欢迎信息
    PHP基础入门教程 PHP循环函数
    php获取客户端ip地址
    PHP获取域名、IP地址的方法
    两日期间的间隔
    mysql 案例 ~ pt-archiver 归档工具的使用
    mysql 案例 ~ pt修复工具的使用
  • 原文地址:https://www.cnblogs.com/laugh/p/6612353.html
Copyright © 2011-2022 走看看