1.加密
- (NSString*)base64String:(NSString*)sourceString
{//判断字符串的长度是否小于等于0如果是,就返回空
if(sourceString.length<=0) {
returnnil;
}
//把字符串转化为二进制流
NSData * sourceData = [[NSData alloc] initWithData:[sourceString dataUsingEncoding:NSUTF8StringEncoding]];
NSString * baseString = [sourceData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
returnbaseString;
}
2.解密
- (NSString*)encodeBase64String:(NSString*)baseString
{
if(baseString.length<=0) {
return nil;
}
NSData * data = [[NSData alloc] initWithBase64EncodedString:baseString options:NSDataBase64DecodingIgnoreUnknownCharacters];
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}