本文转自:https://itony.me/488.html
NSData *nsdata = [@"iOS Developer Tips encode in Base64" dataUsingEncoding:NSUTF8StringEncoding];
//根据NSData生成Base64编码的String
NSString *base64Encode = [nsdata base64EncodedStringWithOptions:0];
NSLog(@"Encode:%@", base64Encode);
//NSData生成未编码的NSString
NSString *noCodeString = [[NSString alloc]initWithData:nsdata encoding:NSUTF8StringEncoding];
NSLog(@"noCodeString:%@",noCodeString);
//NSData from the base64 encoded str
NSData *nsdataFromBase64String = [[NSData alloc]initWithBase64EncodedString:base64Encode options:0];
//Decode NSString from NSData
NSString *base64Decode = [[NSString alloc]initWithData:nsdata encoding:NSUTF8StringEncoding];
NSLog(@"base64Decode:%@",base64Decode);