【代碼筆記】3DES+Base64加密解密,3desbase64
一,工程目錄。
二,代碼。
RootViewController.m
#import "RootViewController.h"#import "NSString+TripleDES.h"#import "GTMBase64.h"@interface RootViewController ()@end@implementation RootViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. self.title=@"3DES+Base64"; //要加密的文字和密碼 NSString *string=@"hello,World"; NSString *key=@"123456"; //加密 NSString *encryString=[NSString stringWithFormat:@"%@",[string EncryptTripleDESWithKey:key]]; NSLog(@"---string--%@",encryString); //解密 NSString *decryString=[NSString stringWithFormat:@"%@",[encryString DecryptTripleDESWithKey:key]]; NSLog(@"--string--%@",decryString); }- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
三,運行效果
2015-10-13 10:29:59.107 3DES+Base64加密解密[2277:66277] ---string--YDcteAUNvtE0PoB6hZpsKg==2015-10-13 10:29:59.108 3DES+Base64加密解密[2277:66277] --string--hello,World