#import "ViewController.h"
#import "NSString+Hashing.h"
@interface ViewController ()
#define Salt @"fsdhjkfhjksdhjkfjhkd546783765"
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self digest:@"123"];
[self digest2:@"123"];
[self digest3:@"123"];
[self digest4:@"123"];
}
//直接用MD5加密
-(NSString *)digest:(NSString *)str
{
NSString *anwen =[str MD5Hash];
NSLog(@"%@-----%@",str,anwen);
return anwen;
}
//加盐
-(NSString *)digest2:(NSString *)str
{
str=[str stringByAppendingString:Salt];
NSString *anwen =[str MD5Hash];
NSLog(@"%@-----%@",str,anwen);
return anwen;
}
//多次MD5
-(NSString *)digest3:(NSString *)str
{
NSString *anwen = [str MD5Hash];
anwen = [anwen MD5Hash];
NSLog(@"%@ - %@", str, anwen);
return anwen;
}
//先加密, 后乱序
-(NSString *)digest4:(NSString *)str
{
NSString *anwen =[str MD5Hash];
NSString *header =[anwen substringFromIndex:2];
NSString *footer=[anwen substringFromIndex:2];
anwen =[footer stringByAppendingString:header];
NSLog(@"%@ - %@", str, anwen);
return anwen;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
网友评论