MD5加密運算

來源:互聯網
上載者:User

標籤:

 1 //MD5 對字串的加密 2 -(void)demo1 { 3     NSString *str = @"love"; 4      5     //對字串進行MD5加密 6     str = str.md5String; 7      8     NSLog(@"str : %@",str); 9     10     //對於比較簡單的密碼,可以通過一些網站查到,如:http://www.cmd5.com11     //人為的增加密碼的難度,可以對 MD5 進行加鹽12     //使用者密碼 + 鹽值   MD5運算13     NSString *password = @"312816";14     //增加鹽值 ,且越長(複雜)越好15     NSString *salt = @"[email protected]#$%^&*sdfgh";16     //給密碼添加鹽值17     password = [password stringByAppendingString:salt];18     //進行 MD5運算19     password = password.md5String;20     21     //加鹽,是一種比較進階的密碼編譯演算法22     NSLog(@"password : %@",password);23 }24 25 //hmac 加密運算26 -(void)demo2 {27     //利用 block 定義一個字串28     __block NSString *password = @"hello";29     30     //建立網路請求,並發送31     NSURL *url = [NSURL URLWithString:@"http://127.0.0.1/login/hmackey.php"];32     33     //發送網路請求34     [[[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {35         //把 JSON資料 轉換成 OC 資料36         NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];37         //定義 hmacKey38         NSString *hmacKey = dict[@"hmacKey"];39         NSLog(@"hmacKey : %@",hmacKey);40         41         //使用從伺服器擷取的 hmacKey 對密碼進行 hmac 運算42         password = [password hmacMD5StringWithKey:hmacKey];43         44         NSLog(@"password : %@",password);45         46     }] resume];47 }

 

MD5加密運算

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.