iPhone开发之BASE64加密和解密

#import <Foundation/Foundation.h>

@interface Base64Code : NSObject
+ (NSString * )encodeBase64:(NSString * )input;//加密
+ (NSString * )decodeBase64:(NSString * )input;//解密
@end

  

#import "Base64Code.h"
#import "GTMBase64.h"

@implementation Base64Code
//加密
+ (NSString * )encodeBase64:(NSString * )input 
{ 
    NSData * data = [input dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; 
    // 转换到base64 
    data = [GTMBase64 encodeData:data]; 
    NSString * base64String = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
    return base64String; 
}

//解密
+ (NSString * )decodeBase64:(NSString * )input 
{ 
    NSData * data = [input dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; 
    // 转换到base64 
    data = [GTMBase64 decodeData:data]; 
    NSString * base64String = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
    return base64String; 
}
@end

  GTMBase64下载地址:http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/

posted @ 2012-05-13 15:16  FoxBabe  阅读(495)  评论(0编辑  收藏  举报