• 了解加密相关


    //
    //  ViewController.m
    //  06 了解加密相关
    //
    //  Created by kun on 16/8/15.
    //  Copyright © 2016年 kun. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"%@", [self base64EncodeString:@"A"]);
        NSLog(@"%@", [self base64AcodeString:[self base64EncodeString:@"A"]]);
    }
    
    // 对一个字符串进行base64编码,并且返回
    - (NSString *)base64EncodeString:(NSString *)string
    {
        // 先转换为二进制数据
        NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
        // 对二进制数据进行base64编码,完成之后返回字符串
        return [data base64EncodedStringWithOptions:0];
    }
    - (NSString *)base64AcodeString:(NSString *)string
    {
        // 注意:该字符串是base64编码后的字符串
        // 转换为二进制数据(完成了解码的过程)
        NSData *data = [[NSData alloc] initWithBase64EncodedString:string options:0];
        // 把二进制数据在转换为字符串
        return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    }
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    Nginx开启Gzip压缩
    VMware克隆虚拟机,克隆机网卡启动不了解决方案
    Linux 几个简单的操作命令
    1. Java环境搭建及demo
    美柚记录
    action找不到
    < >
    document 写法
    develop process
    git stash
  • 原文地址:https://www.cnblogs.com/fkunlam/p/5772513.html
Copyright © 2020-2023  润新知