ViewController.m
// // ViewController.m // Base64 // // Created by dllo on 16/1/12. // Copyright © 2016年 HaiTeng. All rights reserved. // #import "ViewController.h" #import "GTMBase64.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor grayColor]; [self Base64]; } - (void)Base64{ //对字符串进行加密,实质上是进行BASE64编码. NSString *encodStr = [GTMBase64 encodeBase64String:@"wanghaiteng504"]; NSLog(@"%@",encodStr); /*加密完毕,打印看看,编码后的效果*/ //解密 NSString *decodeStr = [GTMBase64 decodeBase64String:encodStr]; NSLog(@"%@",decodeStr); // // //字典加密 // NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"583267034",@"Username",@"wanghaiteng504",@"Userpass", nil]; // //字典转化为Data // NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil]; // NSData *encodeData = [GTMBase64 encodeData:data]; // NSLog(@"%@",encodeData); // // //解密 // NSData *decodeData = [GTMBase64 decodeData:encodeData]; // NSDictionary *di = [NSJSONSerialization JSONObjectWithData:decodeData options:0 error:nil]; // NSLog(@"%@",di); } @end
时间: 2024-10-13 06:00:14