最简单的一种是使用您自己的加密,例如
实用程序.h
@interface Utils : NSObject
+(NSString*)encyptString:(NSString*)str;
+(NSString*)decryptString:(NSString*)str;
@end
实用程序
#import "Utils.h"
int offset = 15;
@implementation Utils
+(NSString*)encyptString:(NSString*)str
{
NSMutableString *encrptedString = [[NSMutableString alloc] init];
for (int i = 0; i < str.length; i++) {
unichar character = [str characterAtIndex:i];
character += offset;
[encrptedString appendFormat:@"%C",character];
}
return encrptedString;
}
+(NSString*)decryptString:(NSString*)str
{
NSMutableString *decrptedString = [[NSMutableString alloc] init];
for (int i = 0; i < str.length; i++) {
unichar character = [str characterAtIndex:i];
character -= offset;
[decrptedString appendFormat:@"%C",character];
}
return decrptedString;
}
@end
如何使用它
NSString *str = @"hello world";
NSString *enr = [Utils encyptString:str];
NSLog(@"Encrypted Text=%@", enr);
NSLog(@"Decrypted Text=%@", [Utils decryptString:enr]);
日志
2013-08-11 10:44:09.409 DeviceTest[445:c07] Encrypted Text=wt{{~/~{s
2013-08-11 10:44:09.412 DeviceTest[445:c07] Decrypted Text=hello world