https cer证书

作者: 失忆的程序员 | 来源:发表于2020-10-16 14:33 被阅读0次

    后台同事给的事.pem和.key文件,项目中要用cer证书,所以要转一下

    pem证书转cer证书 命令:

    1.openssl pkcs12 -export -out cacert.p12 -in cacert.pem -inkey cacert.key   先转p12

    2.openssl pkcs12 -in cacert.p12 -out mycerts.crt -nokeys -clcerts    再转crt

    3.openssl x509 -inform pem -in mycerts.crt -outform der -out mycerts.cer  最后转cer

    下面是你要改的 代码  大概哈  我和你的代码 不是很绝对一样,

    如果报错 信息 :Thread 1: Exception: "A security policy configured with `AFSSLPinningModeCertificate` can only be ap

    需要改成下面的啦

    // 先导入证书 证书由服务端生成,具体由服务端人员操作

        NSString *cerPathStr = [[NSBundle mainBundle] pathForResource:cerPath ofType:@"cer"];//证书的路径

        NSData *cerData = [NSData dataWithContentsOfFile:cerPathStr];

        //使用证书验证模式

        AFSecurityPolicy *securitypolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];

        //如果需要验证自建证书(无效证书),需要设置为YES

        securitypolicy.allowInvalidCertificates = YES;

        //是否需要验证域名,默认为YES

        securitypolicy.validatesDomainName = validatesDomainName;

        securitypolicy.pinnedCertificates = [[NSSet alloc]initWithObjects:cerData, nil];

        [_sessionManager setSecurityPolicy:securitypolicy];

    _sessionManager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:BASE_API_URL]];

    可以参考这些文章 :https://www.cnblogs.com/frounk/p/9373360.html

    相关文章

      网友评论

        本文标题:https cer证书

        本文链接:https://www.haomeiwen.com/subject/fhmzpktx.html