码迷,mamicode.com
首页 > 其他好文 > 详细

了解加密相关

时间:2016-08-15 14:16:55      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

//
//  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

 

了解加密相关

标签:

原文地址:http://www.cnblogs.com/fkunlam/p/5772513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!