美文网首页
iOS MD5加密

iOS MD5加密

作者: 不会学习的睿睿 | 来源:发表于2016-03-09 14:28 被阅读293次

    #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

    相关文章

      网友评论

          本文标题:iOS MD5加密

          本文链接:https://www.haomeiwen.com/subject/nkzzkttx.html