Base64转码
NSData* originData = [originStr dataUsingEncoding:NSASCIIStringEncoding];
NSString* encodeResult = [originData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
NSLog(@"encodeResult:%@",encodeResult);
NSData* decodeData = [[NSData alloc] initWithBase64EncodedString:encodeResult options:0];
NSString* decodeStr = [[NSString alloc] initWithData:decodeData encoding:NSASCIIStringEncoding];
iOS 使用开源库 GTMBase64 转码
/**
*GTM 转码
*/
-(void)GTMEncodeTest
{
NSString* originStr = @"Man";
NSString* encodeResult = nil;
NSData* originData = [originStr dataUsingEncoding:NSUTF8StringEncoding];
NSData* encodeData = [GTMBase64 encodeData:originData];
encodeResult = [[NSString alloc] initWithData:encodeData encoding:NSUTF8StringEncoding];
NSLog(@"%@",encodeResult);
}
/**
* GTM 解码
*/
-(void)GMTDecodeTest
{
NSString* encodeStr = @"TWFu";
NSString* decodeResult = nil;
NSData* encodeData = [encodeStr dataUsingEncoding:NSUTF8StringEncoding];
NSData* decodeData = [GTMBase64 decodeData:encodeData];
decodeResult = [[NSString alloc] initWithData:decodeData encoding:NSUTF8StringEncoding];
NSLog(@"%@",decodeResult);
}
版权声明:本文为博主原创文章,未经博主允许不得转载。