├── 01-GET请求(附带参数) ├── .DS_Store ├── 01-GET请求(附带参数).xcodeproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── wangpengfei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── wangpengfei.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── 01-GET请求(附带参数).xcscheme └── 01-GET请求(附带参数) │ ├── ViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── ViewController.m │ ├── Info.plist │ ├── Base.lproj │ ├── Main.storyboard │ └── LaunchScreen.storyboard │ └── AppDelegate.m ├── 10-钥匙串访问 ├── 10-钥匙串访问 │ ├── SSKeychain │ │ ├── en.lproj │ │ │ └── SSKeychain.strings │ │ ├── SSKeychain.m │ │ ├── SSKeychainQuery.h │ │ └── SSKeychain.h │ ├── ViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── ViewController.m │ ├── Info.plist │ ├── Base.lproj │ │ ├── Main.storyboard │ │ └── LaunchScreen.storyboard │ └── AppDelegate.m └── 10-钥匙串访问.xcodeproj │ ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── wangpengfei.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ └── wangpengfei.xcuserdatad │ └── xcschemes │ ├── xcschememanagement.plist │ └── 10-钥匙串访问.xcscheme ├── 07-MD5加密 ├── 07-MD5加密.xcodeproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── wangpengfei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── wangpengfei.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── 07-MD5加密.xcscheme └── 07-MD5加密 │ ├── ViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── ViewController.m │ ├── Info.plist │ ├── Base.lproj │ ├── Main.storyboard │ └── LaunchScreen.storyboard │ ├── AppDelegate.m │ └── Security │ ├── NSString+Hash.h │ └── NSString+Hash.m ├── 03-base64加密 ├── 03-base64加密.xcodeproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── wangpengfei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── wangpengfei.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── 03-base64加密.xcscheme └── 03-base64加密 │ ├── ViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Info.plist │ ├── Base.lproj │ ├── Main.storyboard │ └── LaunchScreen.storyboard │ ├── AppDelegate.m │ └── ViewController.m ├── 02-POST请求(附带参数) ├── 02-POST请求(附带参数).xcodeproj │ ├── project.xcworkspace │ │ ├── xcuserdata │ │ │ └── wangpengfei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── contents.xcworkspacedata │ └── xcuserdata │ │ └── wangpengfei.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── 02-POST请求(附带参数).xcscheme └── 02-POST请求(附带参数) │ ├── ViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Info.plist │ ├── Base.lproj │ ├── Main.storyboard │ └── LaunchScreen.storyboard │ ├── AppDelegate.m │ └── ViewController.m ├── 08-动态密码(时间戳密码) ├── 08-动态密码(时间戳密码).xcodeproj │ ├── project.xcworkspace │ │ ├── xcuserdata │ │ │ └── wangpengfei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── contents.xcworkspacedata │ └── xcuserdata │ │ └── wangpengfei.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── 08-动态密码(时间戳密码).xcscheme └── 08-动态密码(时间戳密码) │ ├── ViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Info.plist │ ├── Base.lproj │ ├── Main.storyboard │ └── LaunchScreen.storyboard │ ├── AppDelegate.m │ ├── ViewController.m │ └── Security │ ├── NSString+Hash.h │ └── NSString+Hash.m ├── 04-POST加密(保存本地数据) ├── 04-POST加密(保存本地数据).xcodeproj │ ├── project.xcworkspace │ │ ├── xcuserdata │ │ │ └── wangpengfei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── contents.xcworkspacedata │ └── xcuserdata │ │ └── wangpengfei.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── 04-POST加密(保存本地数据).xcscheme └── 04-POST加密(保存本地数据) │ ├── ViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Info.plist │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── AppDelegate.m │ └── ViewController.m ├── 05-POST加密(登录业务逻辑) ├── 04-POST加密(保存本地数据).xcodeproj │ ├── project.xcworkspace │ │ ├── xcuserdata │ │ │ └── wangpengfei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── contents.xcworkspacedata │ └── xcuserdata │ │ └── wangpengfei.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── 04-POST加密(保存本地数据).xcscheme └── 04-POST加密(保存本地数据) │ ├── ViewController.h │ ├── WPFTableViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Info.plist │ ├── Base.lproj │ └── LaunchScreen.storyboard │ ├── AppDelegate.m │ ├── WPFTableViewController.m │ ├── ViewController.m │ └── Main.storyboard └── 06-POST加密(Token值) ├── 04-POST加密(保存本地数据).xcodeproj ├── project.xcworkspace │ ├── xcuserdata │ │ └── wangpengfei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── contents.xcworkspacedata └── xcuserdata │ └── wangpengfei.xcuserdatad │ └── xcschemes │ ├── xcschememanagement.plist │ └── 04-POST加密(保存本地数据).xcscheme └── 04-POST加密(保存本地数据) ├── ViewController.h ├── WPFTableViewController.h ├── AppDelegate.h ├── main.m ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Info.plist ├── Base.lproj └── LaunchScreen.storyboard ├── AppDelegate.m ├── ViewController.m ├── Main.storyboard └── WPFTableViewController.m /01-GET请求(附带参数)/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PengfeiWang666/Security/HEAD/01-GET请求(附带参数)/.DS_Store -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/SSKeychain/en.lproj/SSKeychain.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PengfeiWang666/Security/HEAD/10-钥匙串访问/10-钥匙串访问/SSKeychain/en.lproj/SSKeychain.strings -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密.xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PengfeiWang666/Security/HEAD/07-MD5加密/07-MD5加密.xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问.xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PengfeiWang666/Security/HEAD/10-钥匙串访问/10-钥匙串访问.xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /03-base64加密/03-base64加密.xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PengfeiWang666/Security/HEAD/03-base64加密/03-base64加密.xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PengfeiWang666/Security/HEAD/01-GET请求(附带参数)/01-GET请求(附带参数).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PengfeiWang666/Security/HEAD/02-POST请求(附带参数)/02-POST请求(附带参数).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 07-MD5加密 4 | // 5 | // Created by 王鹏飞 on 16/2/17. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PengfeiWang666/Security/HEAD/08-动态密码(时间戳密码)/08-动态密码(时间戳密码).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 10-钥匙串访问 4 | // 5 | // Created by 王鹏飞 on 16/2/18. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 03-base64加密 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PengfeiWang666/Security/HEAD/04-POST加密(保存本地数据)/04-POST加密(保存本地数据).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PengfeiWang666/Security/HEAD/05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PengfeiWang666/Security/HEAD/06-POST加密(Token值)/04-POST加密(保存本地数据).xcodeproj/project.xcworkspace/xcuserdata/wangpengfei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数)/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 01-GET请求(附带参数) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数)/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 02-POST请求(附带参数) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码)/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 08-动态密码(时间戳密码) 4 | // 5 | // Created by 王鹏飞 on 16/2/17. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据)/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据)/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据)/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据)/WPFTableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // WPFTableViewController.h 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WPFTableViewController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据)/WPFTableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // WPFTableViewController.h 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WPFTableViewController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 07-MD5加密 4 | // 5 | // Created by 王鹏飞 on 16/2/17. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 10-钥匙串访问 4 | // 5 | // Created by 王鹏飞 on 16/2/18. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 03-base64加密 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数)/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 01-GET请求(附带参数) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码)/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 08-动态密码(时间戳密码) 4 | // 5 | // Created by 王鹏飞 on 16/2/17. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数)/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 02-POST请求(附带参数) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据)/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据)/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据)/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 07-MD5加密 4 | // 5 | // Created by 王鹏飞 on 16/2/17. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 10-钥匙串访问 4 | // 5 | // Created by 王鹏飞 on 16/2/18. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 03-base64加密 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 01-GET请求(附带参数) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 08-动态密码(时间戳密码) 4 | // 5 | // Created by 王鹏飞 on 16/2/17. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 02-POST请求(附带参数) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密.xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密.xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 07-MD5加密.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 0FFAC7951C73813C004A9063 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问.xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 10-钥匙串访问.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 0FF15F121C75A3CD00F0D37A 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密.xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03-base64加密.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 0F81E2BB1C73499400AC5B80 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 01-GET请求(附带参数).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 0F81E2751C7337E000AC5B80 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 08-动态密码(时间戳密码).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 0FFAC7BC1C7385DC004A9063 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 02-POST请求(附带参数).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 0F81E2981C733FF000AC5B80 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 04-POST加密(保存本地数据).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 0FFAC76D1C73659D004A9063 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 04-POST加密(保存本地数据).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 0FFAC76D1C73659D004A9063 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 04-POST加密(保存本地数据).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 0FFAC76D1C73659D004A9063 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /03-base64加密/03-base64加密/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数)/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数)/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码)/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据)/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据)/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据)/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 07-MD5加密 4 | // 5 | // Created by 王鹏飞 on 16/2/17. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "NSString+Hash.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | } 22 | 23 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 24 | 25 | // MD5加密现在一般不用于加密,多用于验证一致性(百度MD5解密,第一个网站进去,数据库伪解密) 26 | // 由于MD5加密的特点,“数字指纹”--- 文件的“指纹”,在文件的下载过程中,用于验证文件是否损坏(是否认为添加木马,篡改文件内容等) 27 | NSString *password = @"WangPengfei"; 28 | 29 | password = [password md5String]; 30 | 31 | NSLog(@"password1:%@", password); 32 | 33 | // 加盐:可以保证 MD5加密之后更加安全 34 | // 每一个公司都有自己的“盐值”,盐值越复杂,越安全 35 | NSString *salt = @"234567890-!@#$%^&*()_+QWERTYUIOP{ASDFGHJKL:XCVBNM<>"; 36 | 37 | [password stringByAppendingString:salt]; 38 | 39 | password = [password md5String]; 40 | 41 | NSLog(@"password2:%@", password); 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 10-钥匙串访问 4 | // 5 | // Created by 王鹏飞 on 16/2/18. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "SSKeychain.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | // 1. 获得app 的唯一标识符 22 | NSString *identifier = [NSBundle mainBundle].bundleIdentifier; 23 | 24 | // 2. 取出钥匙串中存储的密码 25 | NSString *password = [SSKeychain passwordForService:identifier account:@"zhangsan"]; 26 | 27 | // 3. 打印密码 28 | NSLog(@"%@", password); 29 | 30 | } 31 | 32 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 33 | 34 | NSLog(@"touchesBegan"); 35 | 36 | /* 37 | 钥匙串存储特点: 38 | 1. 只存储私密信息(密码) 39 | 2. 私密信息可以直接以明文的形式存储 40 | 3.钥匙串的位置不知道在哪里,在钥匙串中存、取数据的时候,依赖于app 41 | 42 | 43 | // 参数 44 | // Password :需要存储的密码信息. 45 | // Service :用来标识 app ,app的唯一标识符. 46 | // account :账户信息,当前密码所对应的账号. 47 | */ 48 | 49 | // 1. 获得app 的唯一标识符 50 | NSString *identifier = [NSBundle mainBundle].bundleIdentifier; 51 | 52 | // 存储密码 53 | [SSKeychain setPassword:@"sssss" forService:identifier account:@"zhangsan"]; 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据)/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSAppTransportSecurity 6 | 7 | NSAllowsArbitraryLoads 8 | 9 | 10 | CFBundleDevelopmentRegion 11 | en 12 | CFBundleExecutable 13 | $(EXECUTABLE_NAME) 14 | CFBundleIdentifier 15 | $(PRODUCT_BUNDLE_IDENTIFIER) 16 | CFBundleInfoDictionaryVersion 17 | 6.0 18 | CFBundleName 19 | $(PRODUCT_NAME) 20 | CFBundlePackageType 21 | APPL 22 | CFBundleShortVersionString 23 | 1.0 24 | CFBundleSignature 25 | ???? 26 | CFBundleVersion 27 | 1 28 | LSRequiresIPhoneOS 29 | 30 | UILaunchStoryboardName 31 | LaunchScreen 32 | UIMainStoryboardFile 33 | Login 34 | UIRequiredDeviceCapabilities 35 | 36 | armv7 37 | 38 | UISupportedInterfaceOrientations 39 | 40 | UIInterfaceOrientationPortrait 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据)/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSAppTransportSecurity 6 | 7 | NSAllowsArbitraryLoads 8 | 9 | 10 | CFBundleDevelopmentRegion 11 | en 12 | CFBundleExecutable 13 | $(EXECUTABLE_NAME) 14 | CFBundleIdentifier 15 | $(PRODUCT_BUNDLE_IDENTIFIER) 16 | CFBundleInfoDictionaryVersion 17 | 6.0 18 | CFBundleName 19 | $(PRODUCT_NAME) 20 | CFBundlePackageType 21 | APPL 22 | CFBundleShortVersionString 23 | 1.0 24 | CFBundleSignature 25 | ???? 26 | CFBundleVersion 27 | 1 28 | LSRequiresIPhoneOS 29 | 30 | UILaunchStoryboardName 31 | LaunchScreen 32 | UIMainStoryboardFile 33 | Login 34 | UIRequiredDeviceCapabilities 35 | 36 | armv7 37 | 38 | UISupportedInterfaceOrientations 39 | 40 | UIInterfaceOrientationPortrait 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数)/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 01-GET请求(附带参数) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view, typically from a nib. 20 | } 21 | 22 | #warning 必须联网才可以实现发送数据的请求 23 | 24 | // 利用 GET 发送数据请求 25 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 26 | 27 | // 1. 创建请求 28 | // http://localhost/login/login.php: 接口地址. 29 | NSString *urlString = @"http://localhost/login/login.php"; 30 | 31 | // 拼接字符串 32 | // username/password:存储账号和密码的key,由服务器后台提供 33 | #warning 这里拼接的字符串需要用 ? 连接 34 | urlString = [urlString stringByAppendingString:@"?password=zhang&username=zhangsan"]; 35 | 36 | NSURL *url = [NSURL URLWithString:urlString]; 37 | 38 | NSURLRequest *request = [NSURLRequest requestWithURL:url]; 39 | 40 | // 2. 发送请求 41 | [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { 42 | 43 | NSLog(@"responseData:%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); 44 | }] resume]; 45 | } 46 | 47 | /* 48 | 打印结果: 49 | 50 | responseData:{"userId":1,"userName":"zhangsan"} 51 | */ 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码)/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSAppTransportSecurity 6 | 7 | 8 | 9 | NSAllowsArbitraryLoads 10 | 11 | 12 | 13 | 14 | CFBundleDevelopmentRegion 15 | en 16 | CFBundleExecutable 17 | $(EXECUTABLE_NAME) 18 | CFBundleIdentifier 19 | $(PRODUCT_BUNDLE_IDENTIFIER) 20 | CFBundleInfoDictionaryVersion 21 | 6.0 22 | CFBundleName 23 | $(PRODUCT_NAME) 24 | CFBundlePackageType 25 | APPL 26 | CFBundleShortVersionString 27 | 1.0 28 | CFBundleSignature 29 | ???? 30 | CFBundleVersion 31 | 1 32 | LSRequiresIPhoneOS 33 | 34 | UILaunchStoryboardName 35 | LaunchScreen 36 | UIMainStoryboardFile 37 | Main 38 | UIRequiredDeviceCapabilities 39 | 40 | armv7 41 | 42 | UISupportedInterfaceOrientations 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数)/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSAppTransportSecurity 6 | 7 | 8 | 9 | NSAllowsArbitraryLoads 10 | 11 | 12 | 13 | 14 | CFBundleDevelopmentRegion 15 | en 16 | CFBundleExecutable 17 | $(EXECUTABLE_NAME) 18 | CFBundleIdentifier 19 | $(PRODUCT_BUNDLE_IDENTIFIER) 20 | CFBundleInfoDictionaryVersion 21 | 6.0 22 | CFBundleName 23 | $(PRODUCT_NAME) 24 | CFBundlePackageType 25 | APPL 26 | CFBundleShortVersionString 27 | 1.0 28 | CFBundleSignature 29 | ???? 30 | CFBundleVersion 31 | 1 32 | LSRequiresIPhoneOS 33 | 34 | UILaunchStoryboardName 35 | LaunchScreen 36 | UIMainStoryboardFile 37 | Main 38 | UIRequiredDeviceCapabilities 39 | 40 | armv7 41 | 42 | UISupportedInterfaceOrientations 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据)/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSAppTransportSecurity 6 | 7 | 8 | 9 | NSAllowsArbitraryLoads 10 | 11 | 12 | 13 | 14 | CFBundleDevelopmentRegion 15 | en 16 | CFBundleExecutable 17 | $(EXECUTABLE_NAME) 18 | CFBundleIdentifier 19 | $(PRODUCT_BUNDLE_IDENTIFIER) 20 | CFBundleInfoDictionaryVersion 21 | 6.0 22 | CFBundleName 23 | $(PRODUCT_NAME) 24 | CFBundlePackageType 25 | APPL 26 | CFBundleShortVersionString 27 | 1.0 28 | CFBundleSignature 29 | ???? 30 | CFBundleVersion 31 | 1 32 | LSRequiresIPhoneOS 33 | 34 | UILaunchStoryboardName 35 | LaunchScreen 36 | UIMainStoryboardFile 37 | Main 38 | UIRequiredDeviceCapabilities 39 | 40 | armv7 41 | 42 | UISupportedInterfaceOrientations 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数)/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSAppTransportSecurity 6 | 7 | 8 | 9 | NSAllowsArbitraryLoads 10 | 11 | 12 | 13 | 14 | 15 | 16 | CFBundleDevelopmentRegion 17 | en 18 | CFBundleExecutable 19 | $(EXECUTABLE_NAME) 20 | CFBundleIdentifier 21 | $(PRODUCT_BUNDLE_IDENTIFIER) 22 | CFBundleInfoDictionaryVersion 23 | 6.0 24 | CFBundleName 25 | $(PRODUCT_NAME) 26 | CFBundlePackageType 27 | APPL 28 | CFBundleShortVersionString 29 | 1.0 30 | CFBundleSignature 31 | ???? 32 | CFBundleVersion 33 | 1 34 | LSRequiresIPhoneOS 35 | 36 | UILaunchStoryboardName 37 | LaunchScreen 38 | UIMainStoryboardFile 39 | Main 40 | UIRequiredDeviceCapabilities 41 | 42 | armv7 43 | 44 | UISupportedInterfaceOrientations 45 | 46 | UIInterfaceOrientationPortrait 47 | UIInterfaceOrientationLandscapeLeft 48 | UIInterfaceOrientationLandscapeRight 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数)/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码)/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数)/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数)/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数)/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码)/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据)/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据)/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据)/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 07-MD5加密 4 | // 5 | // Created by 王鹏飞 on 16/2/17. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 10-钥匙串访问 4 | // 5 | // Created by 王鹏飞 on 16/2/18. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 03-base64加密 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数)/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 01-GET请求(附带参数) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码)/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 08-动态密码(时间戳密码) 4 | // 5 | // Created by 王鹏飞 on 16/2/17. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数)/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 02-POST请求(附带参数) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据)/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 03-base64加密 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view, typically from a nib. 20 | } 21 | 22 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 23 | 24 | // 加密字符串 25 | NSString *string = @"I MISS YOU"; 26 | 27 | NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; 28 | 29 | NSLog(@"data:%@", data); 30 | 31 | // 进行base64 加密 32 | // NSData *base64Data = [data base64EncodedDataWithOptions:0]; 33 | 34 | NSString *base64String = [data base64EncodedStringWithOptions:0]; 35 | 36 | NSLog(@"base64Data:%@", base64String); 37 | 38 | // 直接将加密后的字符串进行base64 解密(可以反向) 39 | NSData *baseData = [[NSData alloc] initWithBase64EncodedString:base64String options:0]; 40 | 41 | // 将解密后产生的二进制数据转为字符串 42 | NSString *baseStr = [[NSString alloc] initWithData:baseData encoding:NSUTF8StringEncoding]; 43 | 44 | NSLog(@"baseStr:%@", baseStr); 45 | 46 | /* 47 | 输出结果: 48 | data:<49204d49 53532059 4f55> 49 | base64Data:SSBNSVNTIFlPVQ== 50 | baseStr:I MISS YOU 51 | */ 52 | 53 | } 54 | 55 | // 解密图片 56 | - (void)test2 { 57 | 58 | // 获得加密后的二进制数据 59 | NSData *base64Data = [NSData dataWithContentsOfFile:@"/Users/wangpengfei/Desktop/123"]; 60 | 61 | // 解密 base64 数据 62 | NSData *baseData = [[NSData alloc] initWithBase64EncodedData:base64Data options:0]; 63 | 64 | // 写入桌面 65 | [baseData writeToFile:@"/Users/wangpengfei/Desktop/IMG_5551.jpg" atomically:YES]; 66 | } 67 | 68 | // 将图片进行加密 69 | - (void)test1 { 70 | 71 | // 获取需要加密文件的二进制数据 72 | NSData *data = [NSData dataWithContentsOfFile:@"/Users/wangpengfei/Desktop/photo/IMG_5551.jpg"]; 73 | 74 | // 打印该图片二进制数据 75 | NSLog(@"data:%@", data); 76 | 77 | // base64 加密是 Xcode7.0 之后出现的 78 | // 或 base64EncodedStringWithOptions 79 | NSData *base64Data = [data base64EncodedDataWithOptions:0]; 80 | 81 | // 将加密后的文件存储到桌面 82 | [base64Data writeToFile:@"/Users/wangpengfei/Desktop/123" atomically:YES]; 83 | } 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码)/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 08-动态密码(时间戳密码) 4 | // 5 | // Created by 王鹏飞 on 16/2/17. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "NSString+Hash.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | // 动态密码:服务器会计算两个时间值,当期时间和前一分钟的时间 22 | 23 | // 为了保证服务器在下一分钟接收到客户端的密码内容之后,仍然能够判断准确的值 24 | } 25 | 26 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 27 | 28 | // 1. 当前密码 29 | NSString *password = @"zhang"; 30 | 31 | // 2. hmacKey值,是对“WangPengfei” 进行 MD5加密之后的值(动态生成的) 32 | NSString *hmacKey = @"d3bba33b51acaa0a272de7a2f6dfa233"; 33 | 34 | // 加密过程 35 | 36 | // 1. 第一次加密:第一次 HMAC 运算 37 | password = [password hmacMD5StringWithKey:hmacKey]; 38 | 39 | // 2.1 获得当前的时间 40 | NSDate *date = [NSDate date]; 41 | 42 | // 2.2 获得当前时间的字符串 43 | // 实例化时间格式器 44 | NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 45 | 46 | // 设置时间格式 47 | formatter.dateFormat = @"yyyy-MM-dd HH:mm"; 48 | 49 | // 获取当前时间(要和服务器保持一致) 50 | NSString *dateStr = [formatter stringFromDate:date]; 51 | 52 | // 3. 将第一次加密后的密码与当前时间的字符串拼接在一起 53 | password = [password stringByAppendingString:dateStr]; 54 | 55 | // 4. 进行第二次 HMAC 加密 56 | password = [password hmacMD5StringWithKey:hmacKey]; 57 | 58 | NSLog(@"password:%@", password); 59 | 60 | 61 | // 访问 loginhmac.php 接口 62 | 63 | // 1. 创建请求 64 | NSURL *url = [NSURL URLWithString:@"http://localhost/login/loginhmac.php"]; 65 | 66 | // POST 要手动设置方法,因此为可变 67 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 68 | 69 | // 设置请求方法 70 | request.HTTPMethod = @"POST"; 71 | 72 | // 设置请求体内容 73 | NSString *body = [NSString stringWithFormat:@"username=zhangsan&password=%@", password]; 74 | 75 | 76 | request.HTTPBody = [body dataUsingEncoding:NSUTF8StringEncoding]; 77 | 78 | // 2. 发送请求 79 | [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { 80 | 81 | NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); 82 | }] resume]; 83 | 84 | 85 | } 86 | 87 | @end 88 | -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数)/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 02-POST请求(附带参数) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | 20 | 21 | // POST 请求是指 向服务器发送表单 22 | 23 | // POST 请求是安全的,在网络中传输私密信息(银行卡信息/密码信息)必须使用 POST 请求 24 | 25 | // 所有的文件(数据量比较大)上传都使用 POST 请求 26 | 27 | // 文件的上传使用 PUT 还是 POST 请求? 利用 POST 来取代 PUT 28 | 29 | // 增(PUT)删(DELETE)改(POST)查(GET),NSURLSession 的上传默认是使用 PUT 请求,所以直接使用 NSUrlSession 中的上传任务不能满足文件上传的需求 30 | 31 | // 评论结构:使用 GET 请求还是 POST 请求? 32 | 33 | // 接口要求: 评论结构中可以附带图片(文件)参数. POST 34 | // 接口要求: 不能附带文件信息,只能附带文字信息. GET / POST(注意字数要求) 35 | } 36 | 37 | // POST 请求发送数据请求 38 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 39 | // 1. 创建请求 40 | NSString *urlString = @"http://localhost/login/login.php"; 41 | 42 | NSURL *url = [NSURL URLWithString:urlString]; 43 | 44 | 45 | // 对于POST请求,必须手动设置其请求方法,因此要使用可变请求 46 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 47 | 48 | // 设置请求方法 49 | request.HTTPMethod = @"POST"; 50 | 51 | #warning 这里的参数不加问号 52 | // 设置请求参数 53 | NSString *body = @"username=zhangsan&password=zhang"; 54 | 55 | NSData *data = [body dataUsingEncoding:NSUTF8StringEncoding]; // 转化为二进制数据 56 | 57 | request.HTTPBody = data; 58 | 59 | // 2. 发送请求 60 | [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { 61 | 62 | NSLog(@"response(响应行/响应头):%@", response); 63 | 64 | NSLog(@"data(实体内容):%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); 65 | }] resume]; 66 | 67 | } 68 | 69 | /* 70 | 打印结果: 71 | 72 | response(响应行/响应头): { URL: http://localhost/login/login.php } { status code: 200, headers { 73 | Connection = "Keep-Alive"; 74 | "Content-Length" = 34; 75 | "Content-Type" = "application/json;charset=utf-8"; 76 | Date = "Tue, 16 Feb 2016 11:51:56 GMT"; 77 | "Keep-Alive" = "timeout=5, max=100"; 78 | Server = "Apache/2.4.16 (Unix) PHP/5.5.27"; 79 | "X-Powered-By" = "PHP/5.5.27"; 80 | } } 81 | 82 | data(实体内容):{"userId":1,"userName":"zhangsan"} 83 | */ 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/SSKeychain/SSKeychain.m: -------------------------------------------------------------------------------- 1 | // 2 | // SSKeychain.m 3 | // SSKeychain 4 | // 5 | // Created by Sam Soffes on 5/19/10. 6 | // Copyright (c) 2010-2014 Sam Soffes. All rights reserved. 7 | // 8 | 9 | #import "SSKeychain.h" 10 | 11 | NSString *const kSSKeychainErrorDomain = @"com.samsoffes.sskeychain"; 12 | NSString *const kSSKeychainAccountKey = @"acct"; 13 | NSString *const kSSKeychainCreatedAtKey = @"cdat"; 14 | NSString *const kSSKeychainClassKey = @"labl"; 15 | NSString *const kSSKeychainDescriptionKey = @"desc"; 16 | NSString *const kSSKeychainLabelKey = @"labl"; 17 | NSString *const kSSKeychainLastModifiedKey = @"mdat"; 18 | NSString *const kSSKeychainWhereKey = @"svce"; 19 | 20 | #if __IPHONE_4_0 && TARGET_OS_IPHONE 21 | static CFTypeRef SSKeychainAccessibilityType = NULL; 22 | #endif 23 | 24 | @implementation SSKeychain 25 | 26 | + (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account { 27 | return [self passwordForService:serviceName account:account error:nil]; 28 | } 29 | 30 | 31 | + (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account error:(NSError *__autoreleasing *)error { 32 | SSKeychainQuery *query = [[SSKeychainQuery alloc] init]; 33 | query.service = serviceName; 34 | query.account = account; 35 | [query fetch:error]; 36 | return query.password; 37 | } 38 | 39 | 40 | + (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account { 41 | return [self deletePasswordForService:serviceName account:account error:nil]; 42 | } 43 | 44 | 45 | + (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account error:(NSError *__autoreleasing *)error { 46 | SSKeychainQuery *query = [[SSKeychainQuery alloc] init]; 47 | query.service = serviceName; 48 | query.account = account; 49 | return [query deleteItem:error]; 50 | } 51 | 52 | 53 | + (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account { 54 | return [self setPassword:password forService:serviceName account:account error:nil]; 55 | } 56 | 57 | 58 | + (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError *__autoreleasing *)error { 59 | SSKeychainQuery *query = [[SSKeychainQuery alloc] init]; 60 | query.service = serviceName; 61 | query.account = account; 62 | query.password = password; 63 | return [query save:error]; 64 | } 65 | 66 | 67 | + (NSArray *)allAccounts { 68 | return [self accountsForService:nil]; 69 | } 70 | 71 | 72 | + (NSArray *)accountsForService:(NSString *)serviceName { 73 | SSKeychainQuery *query = [[SSKeychainQuery alloc] init]; 74 | query.service = serviceName; 75 | return [query fetchAll:nil]; 76 | } 77 | 78 | 79 | #if __IPHONE_4_0 && TARGET_OS_IPHONE 80 | + (CFTypeRef)accessibilityType { 81 | return SSKeychainAccessibilityType; 82 | } 83 | 84 | 85 | + (void)setAccessibilityType:(CFTypeRef)accessibilityType { 86 | CFRetain(accessibilityType); 87 | if (SSKeychainAccessibilityType) { 88 | CFRelease(SSKeychainAccessibilityType); 89 | } 90 | SSKeychainAccessibilityType = accessibilityType; 91 | } 92 | #endif 93 | 94 | @end 95 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密/Security/NSString+Hash.h: -------------------------------------------------------------------------------- 1 | // 01-数据安全 2 | 3 | #import 4 | 5 | @interface NSString (Hash) 6 | 7 | #pragma mark - 散列函数 8 | /** 9 | * 计算MD5散列结果 10 | * 11 | * 终端测试命令: 12 | * @code 13 | * md5 -s "string" 14 | * @endcode 15 | * 16 | *

提示:随着 MD5 碰撞生成器的出现,MD5 算法不应被用于任何软件完整性检查或代码签名的用途。

17 | * 18 | * @return 32个字符的MD5散列字符串 19 | */ 20 | - (NSString *)md5String; 21 | 22 | /** 23 | * 计算SHA1散列结果 24 | * 25 | * 终端测试命令: 26 | * @code 27 | * echo -n "string" | openssl sha -sha1 28 | * @endcode 29 | * 30 | * @return 40个字符的SHA1散列字符串 31 | */ 32 | - (NSString *)sha1String; 33 | 34 | /** 35 | * 计算SHA256散列结果 36 | * 37 | * 终端测试命令: 38 | * @code 39 | * echo -n "string" | openssl sha -sha256 40 | * @endcode 41 | * 42 | * @return 64个字符的SHA256散列字符串 43 | */ 44 | - (NSString *)sha256String; 45 | 46 | /** 47 | * 计算SHA 512散列结果 48 | * 49 | * 终端测试命令: 50 | * @code 51 | * echo -n "string" | openssl sha -sha512 52 | * @endcode 53 | * 54 | * @return 128个字符的SHA 512散列字符串 55 | */ 56 | - (NSString *)sha512String; 57 | 58 | #pragma mark - HMAC 散列函数 59 | /** 60 | * 计算HMAC MD5散列结果 61 | * 62 | * 终端测试命令: 63 | * @code 64 | * echo -n "string" | openssl dgst -md5 -hmac "key" 65 | * @endcode 66 | * 67 | * @return 32个字符的HMAC MD5散列字符串 68 | */ 69 | - (NSString *)hmacMD5StringWithKey:(NSString *)key; 70 | 71 | /** 72 | * 计算HMAC SHA1散列结果 73 | * 74 | * 终端测试命令: 75 | * @code 76 | * echo -n "string" | openssl sha -sha1 -hmac "key" 77 | * @endcode 78 | * 79 | * @return 40个字符的HMAC SHA1散列字符串 80 | */ 81 | - (NSString *)hmacSHA1StringWithKey:(NSString *)key; 82 | 83 | /** 84 | * 计算HMAC SHA256散列结果 85 | * 86 | * 终端测试命令: 87 | * @code 88 | * echo -n "string" | openssl sha -sha256 -hmac "key" 89 | * @endcode 90 | * 91 | * @return 64个字符的HMAC SHA256散列字符串 92 | */ 93 | - (NSString *)hmacSHA256StringWithKey:(NSString *)key; 94 | 95 | /** 96 | * 计算HMAC SHA512散列结果 97 | * 98 | * 终端测试命令: 99 | * @code 100 | * echo -n "string" | openssl sha -sha512 -hmac "key" 101 | * @endcode 102 | * 103 | * @return 128个字符的HMAC SHA512散列字符串 104 | */ 105 | - (NSString *)hmacSHA512StringWithKey:(NSString *)key; 106 | 107 | #pragma mark - 文件散列函数 108 | 109 | /** 110 | * 计算文件的MD5散列结果 111 | * 112 | * 终端测试命令: 113 | * @code 114 | * md5 file.dat 115 | * @endcode 116 | * 117 | * @return 32个字符的MD5散列字符串 118 | */ 119 | - (NSString *)fileMD5Hash; 120 | 121 | /** 122 | * 计算文件的SHA1散列结果 123 | * 124 | * 终端测试命令: 125 | * @code 126 | * openssl sha -sha1 file.dat 127 | * @endcode 128 | * 129 | * @return 40个字符的SHA1散列字符串 130 | */ 131 | - (NSString *)fileSHA1Hash; 132 | 133 | /** 134 | * 计算文件的SHA256散列结果 135 | * 136 | * 终端测试命令: 137 | * @code 138 | * openssl sha -sha256 file.dat 139 | * @endcode 140 | * 141 | * @return 64个字符的SHA256散列字符串 142 | */ 143 | - (NSString *)fileSHA256Hash; 144 | 145 | /** 146 | * 计算文件的SHA512散列结果 147 | * 148 | * 终端测试命令: 149 | * @code 150 | * openssl sha -sha512 file.dat 151 | * @endcode 152 | * 153 | * @return 128个字符的SHA512散列字符串 154 | */ 155 | - (NSString *)fileSHA512Hash; 156 | 157 | @end 158 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码)/Security/NSString+Hash.h: -------------------------------------------------------------------------------- 1 | // 01-数据安全 2 | 3 | #import 4 | 5 | @interface NSString (Hash) 6 | 7 | #pragma mark - 散列函数 8 | /** 9 | * 计算MD5散列结果 10 | * 11 | * 终端测试命令: 12 | * @code 13 | * md5 -s "string" 14 | * @endcode 15 | * 16 | *

提示:随着 MD5 碰撞生成器的出现,MD5 算法不应被用于任何软件完整性检查或代码签名的用途。

17 | * 18 | * @return 32个字符的MD5散列字符串 19 | */ 20 | - (NSString *)md5String; 21 | 22 | /** 23 | * 计算SHA1散列结果 24 | * 25 | * 终端测试命令: 26 | * @code 27 | * echo -n "string" | openssl sha -sha1 28 | * @endcode 29 | * 30 | * @return 40个字符的SHA1散列字符串 31 | */ 32 | - (NSString *)sha1String; 33 | 34 | /** 35 | * 计算SHA256散列结果 36 | * 37 | * 终端测试命令: 38 | * @code 39 | * echo -n "string" | openssl sha -sha256 40 | * @endcode 41 | * 42 | * @return 64个字符的SHA256散列字符串 43 | */ 44 | - (NSString *)sha256String; 45 | 46 | /** 47 | * 计算SHA 512散列结果 48 | * 49 | * 终端测试命令: 50 | * @code 51 | * echo -n "string" | openssl sha -sha512 52 | * @endcode 53 | * 54 | * @return 128个字符的SHA 512散列字符串 55 | */ 56 | - (NSString *)sha512String; 57 | 58 | #pragma mark - HMAC 散列函数 59 | /** 60 | * 计算HMAC MD5散列结果 61 | * 62 | * 终端测试命令: 63 | * @code 64 | * echo -n "string" | openssl dgst -md5 -hmac "key" 65 | * @endcode 66 | * 67 | * @return 32个字符的HMAC MD5散列字符串 68 | */ 69 | - (NSString *)hmacMD5StringWithKey:(NSString *)key; 70 | 71 | /** 72 | * 计算HMAC SHA1散列结果 73 | * 74 | * 终端测试命令: 75 | * @code 76 | * echo -n "string" | openssl sha -sha1 -hmac "key" 77 | * @endcode 78 | * 79 | * @return 40个字符的HMAC SHA1散列字符串 80 | */ 81 | - (NSString *)hmacSHA1StringWithKey:(NSString *)key; 82 | 83 | /** 84 | * 计算HMAC SHA256散列结果 85 | * 86 | * 终端测试命令: 87 | * @code 88 | * echo -n "string" | openssl sha -sha256 -hmac "key" 89 | * @endcode 90 | * 91 | * @return 64个字符的HMAC SHA256散列字符串 92 | */ 93 | - (NSString *)hmacSHA256StringWithKey:(NSString *)key; 94 | 95 | /** 96 | * 计算HMAC SHA512散列结果 97 | * 98 | * 终端测试命令: 99 | * @code 100 | * echo -n "string" | openssl sha -sha512 -hmac "key" 101 | * @endcode 102 | * 103 | * @return 128个字符的HMAC SHA512散列字符串 104 | */ 105 | - (NSString *)hmacSHA512StringWithKey:(NSString *)key; 106 | 107 | #pragma mark - 文件散列函数 108 | 109 | /** 110 | * 计算文件的MD5散列结果 111 | * 112 | * 终端测试命令: 113 | * @code 114 | * md5 file.dat 115 | * @endcode 116 | * 117 | * @return 32个字符的MD5散列字符串 118 | */ 119 | - (NSString *)fileMD5Hash; 120 | 121 | /** 122 | * 计算文件的SHA1散列结果 123 | * 124 | * 终端测试命令: 125 | * @code 126 | * openssl sha -sha1 file.dat 127 | * @endcode 128 | * 129 | * @return 40个字符的SHA1散列字符串 130 | */ 131 | - (NSString *)fileSHA1Hash; 132 | 133 | /** 134 | * 计算文件的SHA256散列结果 135 | * 136 | * 终端测试命令: 137 | * @code 138 | * openssl sha -sha256 file.dat 139 | * @endcode 140 | * 141 | * @return 64个字符的SHA256散列字符串 142 | */ 143 | - (NSString *)fileSHA256Hash; 144 | 145 | /** 146 | * 计算文件的SHA512散列结果 147 | * 148 | * 终端测试命令: 149 | * @code 150 | * openssl sha -sha512 file.dat 151 | * @endcode 152 | * 153 | * @return 128个字符的SHA512散列字符串 154 | */ 155 | - (NSString *)fileSHA512Hash; 156 | 157 | @end 158 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据)/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | #define kUserNameKey @"kUserNameKey" 12 | #define kPasswordKey @"kPasswordKey" 13 | 14 | @interface AppDelegate () 15 | 16 | @end 17 | 18 | @implementation AppDelegate 19 | 20 | 21 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 22 | 23 | // 1. 注册登录成功的通知观察者 24 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:@"loginSuccess" object:nil]; 25 | 26 | // 2. 注册登录成功的通知观察者 27 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccess) name:@"logoutSuccess" object:nil]; 28 | 29 | // 每次app打开后,应该展示给用户哪个界面 30 | // 3. 利用偏好设置中用户保存的信息来判断用户的登录状态 31 | NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:kUserNameKey]; 32 | 33 | NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:kPasswordKey]; 34 | 35 | if (userName && password) { 36 | // 显示app 主界面 37 | [self loginSuccess]; 38 | } else { 39 | 40 | [self logoutSuccess]; 41 | } 42 | 43 | return YES; 44 | } 45 | 46 | // 登录成功 47 | - (void)loginSuccess { 48 | 49 | NSLog(@"登录成功!"); 50 | 51 | // 获取主界面 52 | UIStoryboard *mainSb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 53 | 54 | // 切换控制器 55 | self.window.rootViewController = mainSb.instantiateInitialViewController; 56 | } 57 | 58 | // 注销成功 59 | - (void)logoutSuccess { 60 | NSLog(@"注销成功!"); 61 | 62 | // 获取登录界面 63 | UIStoryboard *loginSb = [UIStoryboard storyboardWithName:@"Login" bundle:nil]; 64 | 65 | // 切换控制器 66 | self.window.rootViewController = loginSb.instantiateInitialViewController; 67 | } 68 | 69 | - (void)applicationWillResignActive:(UIApplication *)application { 70 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 71 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 72 | } 73 | 74 | - (void)applicationDidEnterBackground:(UIApplication *)application { 75 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 76 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 77 | } 78 | 79 | - (void)applicationWillEnterForeground:(UIApplication *)application { 80 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 81 | } 82 | 83 | - (void)applicationDidBecomeActive:(UIApplication *)application { 84 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 85 | } 86 | 87 | - (void)applicationWillTerminate:(UIApplication *)application { 88 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 89 | } 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据)/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | #define kUserNameKey @"kUserNameKey" 12 | #define kPasswordKey @"kPasswordKey" 13 | 14 | @interface AppDelegate () 15 | 16 | @end 17 | 18 | @implementation AppDelegate 19 | 20 | 21 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 22 | 23 | // 1. 注册登录成功的通知观察者 24 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:@"loginSuccess" object:nil]; 25 | 26 | // 2. 注册登录成功的通知观察者 27 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccess) name:@"logoutSuccess" object:nil]; 28 | 29 | // 每次app打开后,应该展示给用户哪个界面 30 | // 3. 利用偏好设置中用户保存的信息来判断用户的登录状态 31 | NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:kUserNameKey]; 32 | 33 | NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:kPasswordKey]; 34 | 35 | if (userName && password) { 36 | // 显示app 主界面 37 | [self loginSuccess]; 38 | } else { 39 | 40 | [self logoutSuccess]; 41 | } 42 | 43 | return YES; 44 | } 45 | 46 | // 登录成功 47 | - (void)loginSuccess { 48 | 49 | NSLog(@"登录成功!"); 50 | 51 | // 获取主界面 52 | UIStoryboard *mainSb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 53 | 54 | // 切换控制器 55 | self.window.rootViewController = mainSb.instantiateInitialViewController; 56 | } 57 | 58 | // 注销成功 59 | - (void)logoutSuccess { 60 | NSLog(@"注销成功!"); 61 | 62 | // 获取登录界面 63 | UIStoryboard *loginSb = [UIStoryboard storyboardWithName:@"Login" bundle:nil]; 64 | 65 | // 切换控制器 66 | self.window.rootViewController = loginSb.instantiateInitialViewController; 67 | } 68 | 69 | - (void)applicationWillResignActive:(UIApplication *)application { 70 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 71 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 72 | } 73 | 74 | - (void)applicationDidEnterBackground:(UIApplication *)application { 75 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 76 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 77 | } 78 | 79 | - (void)applicationWillEnterForeground:(UIApplication *)application { 80 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 81 | } 82 | 83 | - (void)applicationDidBecomeActive:(UIApplication *)application { 84 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 85 | } 86 | 87 | - (void)applicationWillTerminate:(UIApplication *)application { 88 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 89 | } 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据)/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #define kUserNameKey @"kUserNameKey" 12 | #define kPasswordKey @"kPasswordKey" 13 | 14 | @interface ViewController () 15 | 16 | @property (weak, nonatomic) IBOutlet UITextField *userName; 17 | @property (weak, nonatomic) IBOutlet UITextField *password; 18 | @end 19 | 20 | @implementation ViewController 21 | 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | 25 | /* 26 | 登录的业务逻辑: 27 | 1> 首次登录,进入登录界面 28 | 2> 首次登录成功,则第二次直接进入app主界面 29 | 3> 首次登录失败,则第二次进入登录界面 30 | 4> 进行注销操作后,清除本地信息,进入登录界面 31 | */ 32 | } 33 | 34 | - (IBAction)btnLoginDidClick:(UIButton *)sender { 35 | 36 | // 如果两个文本框均不为空,则进行登录操作 37 | if (self.userName.text.length && self.password.text.length) { 38 | 39 | // 1. 创建请求 40 | NSString *urlString = @"http://localhost/login/login.php"; 41 | 42 | NSURL *url = [NSURL URLWithString:urlString]; 43 | 44 | // POST 请求需要手动设置请求方法,因此为可变请求 45 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 46 | 47 | // 设置请求方法 48 | request.HTTPMethod = @"POST"; 49 | 50 | // 设置请求参数 51 | NSString *body = [NSString stringWithFormat:@"username=%@&password=%@", self.userName.text, self.password.text]; 52 | 53 | // 将字符串转为二进制数据 54 | NSData *bodyData = [body dataUsingEncoding:NSUTF8StringEncoding]; 55 | 56 | // 设置请求主体(二进制数据) 57 | request.HTTPBody = bodyData; 58 | 59 | // 2. 发送请求 60 | [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { 61 | 62 | // 打印请求结果 63 | NSLog(@"data:%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); 64 | 65 | // 判断是否登录成功 66 | if (data && !error) { 67 | NSLog(@"网络请求成功!"); 68 | 69 | NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; 70 | 71 | if (dict[@"userID"]) { 72 | [self saveLocalUserInfo]; 73 | } 74 | } else { 75 | NSLog(@"网络请求失败!"); 76 | } 77 | 78 | }] resume]; 79 | } else { 80 | NSLog(@"用户名或密码不能为空!"); 81 | } 82 | } 83 | 84 | // 抽取出读取数据的方法 85 | - (void)readLocalUserInfo { 86 | 87 | // 1. 实例化偏好设置对象 88 | NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; 89 | 90 | // 2. 取出数据进行赋值 91 | self.userName.text = [userDefaults objectForKey:kUserNameKey]; 92 | 93 | // 此时读取的是加密后的密码 94 | self.password.text = [userDefaults objectForKey:kPasswordKey]; 95 | } 96 | 97 | // 抽取出存储数据的方法 98 | - (void)saveLocalUserInfo { 99 | 100 | // 1. 实例化偏好设置对象 101 | NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; 102 | 103 | // 2. 存储用户名 104 | [userDefaults setObject:self.userName.text forKey:kUserNameKey]; 105 | 106 | // 3. 将密码进行base64 加密 107 | // 将密码转化为二进制数据 108 | NSData *data = [self.password.text dataUsingEncoding:NSUTF8StringEncoding]; 109 | 110 | // 进行加密 111 | NSString *base64Str = [data base64EncodedStringWithOptions:0]; 112 | 113 | // 4. 将加密后的密码存储到偏好设置 114 | [userDefaults setObject:base64Str forKey:kPasswordKey]; 115 | 116 | // 5. 为了保证线程的一致性,无论是存储还是读取数据,都要进行同步 117 | [userDefaults synchronize]; 118 | } 119 | 120 | @end 121 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据)/WPFTableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // WPFTableViewController.m 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "WPFTableViewController.h" 10 | 11 | #define kUserNameKey @"kUserNameKey" 12 | #define kPasswordKey @"kPasswordKey" 13 | 14 | @interface WPFTableViewController () 15 | 16 | @end 17 | 18 | @implementation WPFTableViewController 19 | 20 | - (IBAction)btnLogoutDidClick:(UIBarButtonItem *)sender { 21 | 22 | // 1. 清除本地信息 23 | [[NSUserDefaults standardUserDefaults] removeObjectForKey:kUserNameKey]; 24 | 25 | [[NSUserDefaults standardUserDefaults] removeObjectForKey:kPasswordKey]; 26 | 27 | // 同步信息 28 | [[NSUserDefaults standardUserDefaults] synchronize]; 29 | 30 | // 2. 发送信息,切换控制器 31 | [[NSNotificationCenter defaultCenter] postNotificationName:@"logoutSuccess" object:nil]; 32 | 33 | } 34 | 35 | - (void)viewDidLoad { 36 | [super viewDidLoad]; 37 | 38 | 39 | } 40 | 41 | - (void)didReceiveMemoryWarning { 42 | [super didReceiveMemoryWarning]; 43 | // Dispose of any resources that can be recreated. 44 | } 45 | 46 | #pragma mark - Table view data source 47 | 48 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 49 | #warning Incomplete implementation, return the number of sections 50 | return 0; 51 | } 52 | 53 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 54 | #warning Incomplete implementation, return the number of rows 55 | return 0; 56 | } 57 | 58 | /* 59 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 60 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath]; 61 | 62 | // Configure the cell... 63 | 64 | return cell; 65 | } 66 | */ 67 | 68 | /* 69 | // Override to support conditional editing of the table view. 70 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 71 | // Return NO if you do not want the specified item to be editable. 72 | return YES; 73 | } 74 | */ 75 | 76 | /* 77 | // Override to support editing the table view. 78 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 79 | if (editingStyle == UITableViewCellEditingStyleDelete) { 80 | // Delete the row from the data source 81 | [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 82 | } else if (editingStyle == UITableViewCellEditingStyleInsert) { 83 | // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 84 | } 85 | } 86 | */ 87 | 88 | /* 89 | // Override to support rearranging the table view. 90 | - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { 91 | } 92 | */ 93 | 94 | /* 95 | // Override to support conditional rearranging of the table view. 96 | - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 97 | // Return NO if you do not want the item to be re-orderable. 98 | return YES; 99 | } 100 | */ 101 | 102 | /* 103 | #pragma mark - Navigation 104 | 105 | // In a storyboard-based application, you will often want to do a little preparation before navigation 106 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 107 | // Get the new view controller using [segue destinationViewController]. 108 | // Pass the selected object to the new view controller. 109 | } 110 | */ 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密.xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/07-MD5加密.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /03-base64加密/03-base64加密.xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/03-base64加密.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问.xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/10-钥匙串访问.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据)/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #define kUserNameKey @"kUserNameKey" 12 | #define kPasswordKey @"kPasswordKey" 13 | 14 | @interface ViewController () 15 | 16 | @property (weak, nonatomic) IBOutlet UITextField *userName; 17 | @property (weak, nonatomic) IBOutlet UITextField *password; 18 | @end 19 | 20 | @implementation ViewController 21 | 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | 25 | /* 26 | 登录的业务逻辑: 27 | 1> 首次登录,进入登录界面 28 | 2> 首次登录成功,则第二次直接进入app主界面 29 | 3> 首次登录失败,则第二次进入登录界面 30 | 4> 进行注销操作后,清除本地信息,进入登录界面 31 | */ 32 | } 33 | 34 | - (IBAction)btnLoginDidClick:(UIButton *)sender { 35 | 36 | // 如果两个文本框均不为空,则进行登录操作 37 | if (self.userName.text.length && self.password.text.length) { 38 | 39 | // 1. 创建请求 40 | NSString *urlString = @"http://localhost/login/login.php"; 41 | 42 | NSURL *url = [NSURL URLWithString:urlString]; 43 | 44 | // POST 请求需要手动设置请求方法,因此为可变请求 45 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 46 | 47 | // 设置请求方法 48 | request.HTTPMethod = @"POST"; 49 | 50 | // 设置请求参数 51 | NSString *body = [NSString stringWithFormat:@"username=%@&password=%@", self.userName.text, self.password.text]; 52 | 53 | // 将字符串转为二进制数据 54 | NSData *bodyData = [body dataUsingEncoding:NSUTF8StringEncoding]; 55 | 56 | // 设置请求主体(二进制数据) 57 | request.HTTPBody = bodyData; 58 | 59 | // 2. 发送请求 60 | [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { 61 | 62 | // 打印请求结果 63 | NSLog(@"data:%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); 64 | 65 | // 判断是否登录成功 66 | if (data && !error) { 67 | NSLog(@"网络请求成功!"); 68 | 69 | NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL]; 70 | 71 | if (dict[@"userId"]) { 72 | [self saveLocalUserInfo]; 73 | 74 | // 跳转到app主界面,在主线程中发送通知 75 | dispatch_async(dispatch_get_main_queue(), ^{ 76 | [[NSNotificationCenter defaultCenter] postNotificationName:@"loginSuccess" object:nil]; 77 | }); 78 | } 79 | } else { 80 | NSLog(@"网络请求失败!"); 81 | } 82 | 83 | }] resume]; 84 | } else { 85 | NSLog(@"用户名或密码不能为空!"); 86 | } 87 | } 88 | 89 | // 抽取出读取数据的方法 90 | - (void)readLocalUserInfo { 91 | 92 | // 1. 实例化偏好设置对象 93 | NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; 94 | 95 | // 2. 取出数据进行赋值 96 | self.userName.text = [userDefaults objectForKey:kUserNameKey]; 97 | 98 | // 此时读取的是加密后的密码 99 | self.password.text = [userDefaults objectForKey:kPasswordKey]; 100 | } 101 | 102 | // 抽取出存储数据的方法 103 | - (void)saveLocalUserInfo { 104 | 105 | // 1. 实例化偏好设置对象 106 | NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; 107 | 108 | // 2. 存储用户名 109 | [userDefaults setObject:self.userName.text forKey:kUserNameKey]; 110 | 111 | // 3. 将密码进行base64 加密 112 | // 将密码转化为二进制数据 113 | NSData *data = [self.password.text dataUsingEncoding:NSUTF8StringEncoding]; 114 | 115 | // 进行加密 116 | NSString *base64Str = [data base64EncodedStringWithOptions:0]; 117 | 118 | // 4. 将加密后的密码存储到偏好设置 119 | [userDefaults setObject:base64Str forKey:kPasswordKey]; 120 | 121 | // 5. 为了保证线程的一致性,无论是存储还是读取数据,都要进行同步 122 | [userDefaults synchronize]; 123 | NSLog(@"saveLocalUserInfo"); 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据)/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #define kUserNameKey @"kUserNameKey" 12 | #define kPasswordKey @"kPasswordKey" 13 | 14 | @interface ViewController () 15 | 16 | @property (weak, nonatomic) IBOutlet UITextField *userName; 17 | @property (weak, nonatomic) IBOutlet UITextField *password; 18 | @end 19 | 20 | @implementation ViewController 21 | 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | 25 | /* 26 | 登录的业务逻辑: 27 | 1> 首次登录,进入登录界面 28 | 2> 首次登录成功,则第二次直接进入app主界面 29 | 3> 首次登录失败,则第二次进入登录界面 30 | 4> 进行注销操作后,清除本地信息,进入登录界面 31 | */ 32 | } 33 | 34 | - (IBAction)btnLoginDidClick:(UIButton *)sender { 35 | 36 | // 如果两个文本框均不为空,则进行登录操作 37 | if (self.userName.text.length && self.password.text.length) { 38 | 39 | // 1. 创建请求 40 | NSString *urlString = @"http://localhost/login/login.php"; 41 | 42 | NSURL *url = [NSURL URLWithString:urlString]; 43 | 44 | // POST 请求需要手动设置请求方法,因此为可变请求 45 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 46 | 47 | // 设置请求方法 48 | request.HTTPMethod = @"POST"; 49 | 50 | // 设置请求参数 51 | NSString *body = [NSString stringWithFormat:@"username=%@&password=%@", self.userName.text, self.password.text]; 52 | 53 | // 将字符串转为二进制数据 54 | NSData *bodyData = [body dataUsingEncoding:NSUTF8StringEncoding]; 55 | 56 | // 设置请求主体(二进制数据) 57 | request.HTTPBody = bodyData; 58 | 59 | // 2. 发送请求 60 | [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { 61 | 62 | // 打印请求结果 63 | NSLog(@"data:%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); 64 | 65 | // 判断是否登录成功 66 | if (data && !error) { 67 | NSLog(@"网络请求成功!"); 68 | 69 | NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL]; 70 | 71 | if (dict[@"userId"]) { 72 | [self saveLocalUserInfo]; 73 | 74 | // 跳转到app主界面,在主线程中发送通知 75 | dispatch_async(dispatch_get_main_queue(), ^{ 76 | [[NSNotificationCenter defaultCenter] postNotificationName:@"loginSuccess" object:nil]; 77 | }); 78 | } 79 | } else { 80 | NSLog(@"网络请求失败!"); 81 | } 82 | 83 | }] resume]; 84 | } else { 85 | NSLog(@"用户名或密码不能为空!"); 86 | } 87 | } 88 | 89 | // 抽取出读取数据的方法 90 | - (void)readLocalUserInfo { 91 | 92 | // 1. 实例化偏好设置对象 93 | NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; 94 | 95 | // 2. 取出数据进行赋值 96 | self.userName.text = [userDefaults objectForKey:kUserNameKey]; 97 | 98 | // 此时读取的是加密后的密码 99 | self.password.text = [userDefaults objectForKey:kPasswordKey]; 100 | } 101 | 102 | // 抽取出存储数据的方法 103 | - (void)saveLocalUserInfo { 104 | 105 | // 1. 实例化偏好设置对象 106 | NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; 107 | 108 | // 2. 存储用户名 109 | [userDefaults setObject:self.userName.text forKey:kUserNameKey]; 110 | 111 | // 3. 将密码进行base64 加密 112 | // 将密码转化为二进制数据 113 | NSData *data = [self.password.text dataUsingEncoding:NSUTF8StringEncoding]; 114 | 115 | // 进行加密 116 | NSString *base64Str = [data base64EncodedStringWithOptions:0]; 117 | 118 | // 4. 将加密后的密码存储到偏好设置 119 | [userDefaults setObject:base64Str forKey:kPasswordKey]; 120 | 121 | // 5. 为了保证线程的一致性,无论是存储还是读取数据,都要进行同步 122 | [userDefaults synchronize]; 123 | NSLog(@"saveLocalUserInfo"); 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /01-GET请求(附带参数)/01-GET请求(附带参数).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/01-GET请求(附带参数).xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /02-POST请求(附带参数)/02-POST请求(附带参数).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/02-POST请求(附带参数).xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/SSKeychain/SSKeychainQuery.h: -------------------------------------------------------------------------------- 1 | // 2 | // SSKeychainQuery.h 3 | // SSKeychain 4 | // 5 | // Created by Caleb Davenport on 3/19/13. 6 | // Copyright (c) 2013-2014 Sam Soffes. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | #if __IPHONE_7_0 || __MAC_10_9 13 | // Keychain synchronization available at compile time 14 | #define SSKEYCHAIN_SYNCHRONIZATION_AVAILABLE 1 15 | #endif 16 | 17 | #ifdef SSKEYCHAIN_SYNCHRONIZATION_AVAILABLE 18 | typedef NS_ENUM(NSUInteger, SSKeychainQuerySynchronizationMode) { 19 | SSKeychainQuerySynchronizationModeAny, 20 | SSKeychainQuerySynchronizationModeNo, 21 | SSKeychainQuerySynchronizationModeYes 22 | }; 23 | #endif 24 | 25 | /** 26 | Simple interface for querying or modifying keychain items. 27 | */ 28 | @interface SSKeychainQuery : NSObject 29 | 30 | /** kSecAttrAccount */ 31 | @property (nonatomic, copy) NSString *account; 32 | 33 | /** kSecAttrService */ 34 | @property (nonatomic, copy) NSString *service; 35 | 36 | /** kSecAttrLabel */ 37 | @property (nonatomic, copy) NSString *label; 38 | 39 | #if __IPHONE_3_0 && TARGET_OS_IPHONE 40 | /** kSecAttrAccessGroup (only used on iOS) */ 41 | @property (nonatomic, copy) NSString *accessGroup; 42 | #endif 43 | 44 | #ifdef SSKEYCHAIN_SYNCHRONIZATION_AVAILABLE 45 | /** kSecAttrSynchronizable */ 46 | @property (nonatomic) SSKeychainQuerySynchronizationMode synchronizationMode; 47 | #endif 48 | 49 | /** Root storage for password information */ 50 | @property (nonatomic, copy) NSData *passwordData; 51 | 52 | /** 53 | This property automatically transitions between an object and the value of 54 | `passwordData` using NSKeyedArchiver and NSKeyedUnarchiver. 55 | */ 56 | @property (nonatomic, copy) id passwordObject; 57 | 58 | /** 59 | Convenience accessor for setting and getting a password string. Passes through 60 | to `passwordData` using UTF-8 string encoding. 61 | */ 62 | @property (nonatomic, copy) NSString *password; 63 | 64 | 65 | ///------------------------ 66 | /// @name Saving & Deleting 67 | ///------------------------ 68 | 69 | /** 70 | Save the receiver's attributes as a keychain item. Existing items with the 71 | given account, service, and access group will first be deleted. 72 | 73 | @param error Populated should an error occur. 74 | 75 | @return `YES` if saving was successful, `NO` otherwise. 76 | */ 77 | - (BOOL)save:(NSError **)error; 78 | 79 | /** 80 | Delete keychain items that match the given account, service, and access group. 81 | 82 | @param error Populated should an error occur. 83 | 84 | @return `YES` if saving was successful, `NO` otherwise. 85 | */ 86 | - (BOOL)deleteItem:(NSError **)error; 87 | 88 | 89 | ///--------------- 90 | /// @name Fetching 91 | ///--------------- 92 | 93 | /** 94 | Fetch all keychain items that match the given account, service, and access 95 | group. The values of `password` and `passwordData` are ignored when fetching. 96 | 97 | @param error Populated should an error occur. 98 | 99 | @return An array of dictionaries that represent all matching keychain items or 100 | `nil` should an error occur. 101 | The order of the items is not determined. 102 | */ 103 | - (NSArray *)fetchAll:(NSError **)error; 104 | 105 | /** 106 | Fetch the keychain item that matches the given account, service, and access 107 | group. The `password` and `passwordData` properties will be populated unless 108 | an error occurs. The values of `password` and `passwordData` are ignored when 109 | fetching. 110 | 111 | @param error Populated should an error occur. 112 | 113 | @return `YES` if fetching was successful, `NO` otherwise. 114 | */ 115 | - (BOOL)fetch:(NSError **)error; 116 | 117 | 118 | ///----------------------------- 119 | /// @name Synchronization Status 120 | ///----------------------------- 121 | 122 | #ifdef SSKEYCHAIN_SYNCHRONIZATION_AVAILABLE 123 | /** 124 | Returns a boolean indicating if keychain synchronization is available on the device at runtime. The #define 125 | SSKEYCHAIN_SYNCHRONIZATION_AVAILABLE is only for compile time. If you are checking for the presence of synchronization, 126 | you should use this method. 127 | 128 | @return A value indicating if keychain synchronization is available 129 | */ 130 | + (BOOL)isSynchronizationAvailable; 131 | #endif 132 | 133 | @end 134 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据)/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据)/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/04-POST加密(保存本地数据).xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /05-POST加密(登录业务逻辑)/04-POST加密(保存本地数据).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/04-POST加密(保存本地数据).xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/04-POST加密(保存本地数据).xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码).xcodeproj/xcuserdata/wangpengfei.xcuserdatad/xcschemes/08-动态密码(时间戳密码).xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /06-POST加密(Token值)/04-POST加密(保存本地数据)/WPFTableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // WPFTableViewController.m 3 | // 04-POST加密(保存本地数据) 4 | // 5 | // Created by 王鹏飞 on 16/2/16. 6 | // Copyright © 2016年 王鹏飞. All rights reserved. 7 | // 8 | 9 | #import "WPFTableViewController.h" 10 | 11 | #define kUserNameKey @"kUserNameKey" 12 | #define kPasswordKey @"kPasswordKey" 13 | 14 | @interface WPFTableViewController () 15 | 16 | @end 17 | 18 | @implementation WPFTableViewController 19 | 20 | - (IBAction)btnLogoutDidClick:(UIBarButtonItem *)sender { 21 | 22 | // 1. 清除本地信息 23 | [[NSUserDefaults standardUserDefaults] removeObjectForKey:kUserNameKey]; 24 | 25 | [[NSUserDefaults standardUserDefaults] removeObjectForKey:kPasswordKey]; 26 | 27 | // 同步信息 28 | [[NSUserDefaults standardUserDefaults] synchronize]; 29 | 30 | // 2. 发送信息,切换控制器 31 | [[NSNotificationCenter defaultCenter] postNotificationName:@"logoutSuccess" object:nil]; 32 | 33 | } 34 | 35 | - (void)viewDidLoad { 36 | [super viewDidLoad]; 37 | 38 | // token 值: 登录令牌.利用 token 值来判断用户的登录状态.类似于 MD5 加密之后的长字符串. 39 | 40 | // 用户登录成功之后,在后端(服务器端)会根据用户信息生成一个唯一的值.这个值就是 token 值. 41 | 42 | // 1. 在服务器端(数据库)会保存这个 token 值,以后利用这个 token 值来检索对应的用户信息,并且判断用户的登录状态. 43 | 44 | // 2. 用户登录成功之后,服务器会将生成的 token 值返回给 客户端,在客户端也会保存这个 token 值.(一般可以保存在 cookie 中,也可以自己手动确定保存位置(比如偏好设置.)). 45 | 46 | // 3. 以后客户端在发送新的网络请求的时候,会默认自动附带这个 token 值(作为一个参数传递给服务器.).服务器拿到客户端传递的 token 值跟保存在 数据库中的 token 值做对比,以此来判断用户身份和登录状态. 47 | 48 | // 判断登录状态: 49 | 50 | // 1. 如果客户端没有这个 token 值,意味着没有登录成功过,提示用户登录. 51 | 52 | // 2. 如果客户端有 token 值,一般会认为登录成功.不需要用户再次登录(输入账号和密码信息). 53 | 54 | // token 值扩展: 55 | 56 | // 1. token 值有失效时间; 一般的 app ,token值得失效时间都在 1 年以上. 57 | // 特殊的 app :银行类 app /支付类 app :token值失效时间 15 分钟左右. 58 | 59 | // 2. token 值改变: 可以做 唯一性登录的判断,也可以检查用户信息的改变. 60 | 61 | // 一旦用户信息改变(密码改变),会在服务器生成新的 token 值,原来的 token值就会失效.需要再次输入账号和密码,以得到生成的新的 token 值. 62 | 63 | // 唯一性判断: 每次登录,都会生成一个新的token值.原来的 token 值就会失效.利用时间来判断登录的差异性. 64 | } 65 | 66 | - (void)didReceiveMemoryWarning { 67 | [super didReceiveMemoryWarning]; 68 | // Dispose of any resources that can be recreated. 69 | } 70 | 71 | #pragma mark - Table view data source 72 | 73 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 74 | #warning Incomplete implementation, return the number of sections 75 | return 0; 76 | } 77 | 78 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 79 | #warning Incomplete implementation, return the number of rows 80 | return 0; 81 | } 82 | 83 | /* 84 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 85 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath]; 86 | 87 | // Configure the cell... 88 | 89 | return cell; 90 | } 91 | */ 92 | 93 | /* 94 | // Override to support conditional editing of the table view. 95 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 96 | // Return NO if you do not want the specified item to be editable. 97 | return YES; 98 | } 99 | */ 100 | 101 | /* 102 | // Override to support editing the table view. 103 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 104 | if (editingStyle == UITableViewCellEditingStyleDelete) { 105 | // Delete the row from the data source 106 | [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 107 | } else if (editingStyle == UITableViewCellEditingStyleInsert) { 108 | // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 109 | } 110 | } 111 | */ 112 | 113 | /* 114 | // Override to support rearranging the table view. 115 | - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { 116 | } 117 | */ 118 | 119 | /* 120 | // Override to support conditional rearranging of the table view. 121 | - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 122 | // Return NO if you do not want the item to be re-orderable. 123 | return YES; 124 | } 125 | */ 126 | 127 | /* 128 | #pragma mark - Navigation 129 | 130 | // In a storyboard-based application, you will often want to do a little preparation before navigation 131 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 132 | // Get the new view controller using [segue destinationViewController]. 133 | // Pass the selected object to the new view controller. 134 | } 135 | */ 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /10-钥匙串访问/10-钥匙串访问/SSKeychain/SSKeychain.h: -------------------------------------------------------------------------------- 1 | // 2 | // SSKeychain.h 3 | // SSKeychain 4 | // 5 | // Created by Sam Soffes on 5/19/10. 6 | // Copyright (c) 2010-2014 Sam Soffes. All rights reserved. 7 | // 8 | 9 | #import "SSKeychainQuery.h" 10 | 11 | /** 12 | Error code specific to SSKeychain that can be returned in NSError objects. 13 | For codes returned by the operating system, refer to SecBase.h for your 14 | platform. 15 | */ 16 | typedef NS_ENUM(OSStatus, SSKeychainErrorCode) { 17 | /** Some of the arguments were invalid. */ 18 | SSKeychainErrorBadArguments = -1001, 19 | }; 20 | 21 | /** SSKeychain error domain */ 22 | extern NSString *const kSSKeychainErrorDomain; 23 | 24 | /** Account name. */ 25 | extern NSString *const kSSKeychainAccountKey; 26 | 27 | /** 28 | Time the item was created. 29 | 30 | The value will be a string. 31 | */ 32 | extern NSString *const kSSKeychainCreatedAtKey; 33 | 34 | /** Item class. */ 35 | extern NSString *const kSSKeychainClassKey; 36 | 37 | /** Item description. */ 38 | extern NSString *const kSSKeychainDescriptionKey; 39 | 40 | /** Item label. */ 41 | extern NSString *const kSSKeychainLabelKey; 42 | 43 | /** Time the item was last modified. 44 | 45 | The value will be a string. 46 | */ 47 | extern NSString *const kSSKeychainLastModifiedKey; 48 | 49 | /** Where the item was created. */ 50 | extern NSString *const kSSKeychainWhereKey; 51 | 52 | /** 53 | Simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system 54 | Keychain on Mac OS X and iOS. 55 | 56 | This was originally inspired by EMKeychain and SDKeychain (both of which are now gone). Thanks to the authors. 57 | SSKeychain has since switched to a simpler implementation that was abstracted from [SSToolkit](http://sstoolk.it). 58 | */ 59 | @interface SSKeychain : NSObject 60 | 61 | #pragma mark - Classic methods 62 | 63 | /** 64 | Returns a string containing the password for a given account and service, or `nil` if the Keychain doesn't have a 65 | password for the given parameters. 66 | 67 | @param serviceName The service for which to return the corresponding password. 68 | 69 | @param account The account for which to return the corresponding password. 70 | 71 | @return Returns a string containing the password for a given account and service, or `nil` if the Keychain doesn't 72 | have a password for the given parameters. 73 | */ 74 | + (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account; 75 | + (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error; 76 | 77 | 78 | /** 79 | Deletes a password from the Keychain. 80 | 81 | @param serviceName The service for which to delete the corresponding password. 82 | 83 | @param account The account for which to delete the corresponding password. 84 | 85 | @return Returns `YES` on success, or `NO` on failure. 86 | */ 87 | + (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account; 88 | + (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error; 89 | 90 | 91 | /** 92 | Sets a password in the Keychain. 93 | 94 | @param password The password to store in the Keychain. 95 | 96 | @param serviceName The service for which to set the corresponding password. 97 | 98 | @param account The account for which to set the corresponding password. 99 | 100 | @return Returns `YES` on success, or `NO` on failure. 101 | */ 102 | + (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account; 103 | + (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error; 104 | 105 | 106 | /** 107 | Returns an array containing the Keychain's accounts, or `nil` if the Keychain has no accounts. 108 | 109 | See the `NSString` constants declared in SSKeychain.h for a list of keys that can be used when accessing the 110 | dictionaries returned by this method. 111 | 112 | @return An array of dictionaries containing the Keychain's accounts, or `nil` if the Keychain doesn't have any 113 | accounts. The order of the objects in the array isn't defined. 114 | */ 115 | + (NSArray *)allAccounts; 116 | 117 | 118 | /** 119 | Returns an array containing the Keychain's accounts for a given service, or `nil` if the Keychain doesn't have any 120 | accounts for the given service. 121 | 122 | See the `NSString` constants declared in SSKeychain.h for a list of keys that can be used when accessing the 123 | dictionaries returned by this method. 124 | 125 | @param serviceName The service for which to return the corresponding accounts. 126 | 127 | @return An array of dictionaries containing the Keychain's accounts for a given `serviceName`, or `nil` if the Keychain 128 | doesn't have any accounts for the given `serviceName`. The order of the objects in the array isn't defined. 129 | */ 130 | + (NSArray *)accountsForService:(NSString *)serviceName; 131 | 132 | 133 | #pragma mark - Configuration 134 | 135 | #if __IPHONE_4_0 && TARGET_OS_IPHONE 136 | /** 137 | Returns the accessibility type for all future passwords saved to the Keychain. 138 | 139 | @return Returns the accessibility type. 140 | 141 | The return value will be `NULL` or one of the "Keychain Item Accessibility 142 | Constants" used for determining when a keychain item should be readable. 143 | 144 | @see setAccessibilityType 145 | */ 146 | + (CFTypeRef)accessibilityType; 147 | 148 | /** 149 | Sets the accessibility type for all future passwords saved to the Keychain. 150 | 151 | @param accessibilityType One of the "Keychain Item Accessibility Constants" 152 | used for determining when a keychain item should be readable. 153 | 154 | If the value is `NULL` (the default), the Keychain default will be used. 155 | 156 | @see accessibilityType 157 | */ 158 | + (void)setAccessibilityType:(CFTypeRef)accessibilityType; 159 | #endif 160 | 161 | @end 162 | -------------------------------------------------------------------------------- /07-MD5加密/07-MD5加密/Security/NSString+Hash.m: -------------------------------------------------------------------------------- 1 | // 01-数据安全 2 | 3 | #import "NSString+Hash.h" 4 | #import 5 | 6 | @implementation NSString (Hash) 7 | 8 | #pragma mark - 散列函数 9 | - (NSString *)md5String { 10 | const char *str = self.UTF8String; 11 | uint8_t buffer[CC_MD5_DIGEST_LENGTH]; 12 | 13 | CC_MD5(str, (CC_LONG)strlen(str), buffer); 14 | 15 | return [self stringFromBytes:buffer length:CC_MD5_DIGEST_LENGTH]; 16 | } 17 | 18 | - (NSString *)sha1String { 19 | const char *str = self.UTF8String; 20 | uint8_t buffer[CC_SHA1_DIGEST_LENGTH]; 21 | 22 | CC_SHA1(str, (CC_LONG)strlen(str), buffer); 23 | 24 | return [self stringFromBytes:buffer length:CC_SHA1_DIGEST_LENGTH]; 25 | } 26 | 27 | - (NSString *)sha256String { 28 | const char *str = self.UTF8String; 29 | uint8_t buffer[CC_SHA256_DIGEST_LENGTH]; 30 | 31 | CC_SHA256(str, (CC_LONG)strlen(str), buffer); 32 | 33 | return [self stringFromBytes:buffer length:CC_SHA256_DIGEST_LENGTH]; 34 | } 35 | 36 | - (NSString *)sha512String { 37 | const char *str = self.UTF8String; 38 | uint8_t buffer[CC_SHA512_DIGEST_LENGTH]; 39 | 40 | CC_SHA512(str, (CC_LONG)strlen(str), buffer); 41 | 42 | return [self stringFromBytes:buffer length:CC_SHA512_DIGEST_LENGTH]; 43 | } 44 | 45 | #pragma mark - HMAC 散列函数 46 | - (NSString *)hmacMD5StringWithKey:(NSString *)key { 47 | const char *keyData = key.UTF8String; 48 | const char *strData = self.UTF8String; 49 | uint8_t buffer[CC_MD5_DIGEST_LENGTH]; 50 | 51 | CCHmac(kCCHmacAlgMD5, keyData, strlen(keyData), strData, strlen(strData), buffer); 52 | 53 | return [self stringFromBytes:buffer length:CC_MD5_DIGEST_LENGTH]; 54 | } 55 | 56 | - (NSString *)hmacSHA1StringWithKey:(NSString *)key { 57 | const char *keyData = key.UTF8String; 58 | const char *strData = self.UTF8String; 59 | uint8_t buffer[CC_SHA1_DIGEST_LENGTH]; 60 | 61 | CCHmac(kCCHmacAlgSHA1, keyData, strlen(keyData), strData, strlen(strData), buffer); 62 | 63 | return [self stringFromBytes:buffer length:CC_SHA1_DIGEST_LENGTH]; 64 | } 65 | 66 | - (NSString *)hmacSHA256StringWithKey:(NSString *)key { 67 | const char *keyData = key.UTF8String; 68 | const char *strData = self.UTF8String; 69 | uint8_t buffer[CC_SHA256_DIGEST_LENGTH]; 70 | 71 | CCHmac(kCCHmacAlgSHA256, keyData, strlen(keyData), strData, strlen(strData), buffer); 72 | 73 | return [self stringFromBytes:buffer length:CC_SHA256_DIGEST_LENGTH]; 74 | } 75 | 76 | - (NSString *)hmacSHA512StringWithKey:(NSString *)key { 77 | const char *keyData = key.UTF8String; 78 | const char *strData = self.UTF8String; 79 | uint8_t buffer[CC_SHA512_DIGEST_LENGTH]; 80 | 81 | CCHmac(kCCHmacAlgSHA512, keyData, strlen(keyData), strData, strlen(strData), buffer); 82 | 83 | return [self stringFromBytes:buffer length:CC_SHA512_DIGEST_LENGTH]; 84 | } 85 | 86 | #pragma mark - 文件散列函数 87 | 88 | #define FileHashDefaultChunkSizeForReadingData 4096 89 | 90 | - (NSString *)fileMD5Hash { 91 | NSFileHandle *fp = [NSFileHandle fileHandleForReadingAtPath:self]; 92 | if (fp == nil) { 93 | return nil; 94 | } 95 | 96 | CC_MD5_CTX hashCtx; 97 | CC_MD5_Init(&hashCtx); 98 | 99 | while (YES) { 100 | @autoreleasepool { 101 | NSData *data = [fp readDataOfLength:FileHashDefaultChunkSizeForReadingData]; 102 | 103 | CC_MD5_Update(&hashCtx, data.bytes, (CC_LONG)data.length); 104 | 105 | if (data.length == 0) { 106 | break; 107 | } 108 | } 109 | } 110 | [fp closeFile]; 111 | 112 | uint8_t buffer[CC_MD5_DIGEST_LENGTH]; 113 | CC_MD5_Final(buffer, &hashCtx); 114 | 115 | return [self stringFromBytes:buffer length:CC_MD5_DIGEST_LENGTH]; 116 | } 117 | 118 | - (NSString *)fileSHA1Hash { 119 | NSFileHandle *fp = [NSFileHandle fileHandleForReadingAtPath:self]; 120 | if (fp == nil) { 121 | return nil; 122 | } 123 | 124 | CC_SHA1_CTX hashCtx; 125 | CC_SHA1_Init(&hashCtx); 126 | 127 | while (YES) { 128 | @autoreleasepool { 129 | NSData *data = [fp readDataOfLength:FileHashDefaultChunkSizeForReadingData]; 130 | 131 | CC_SHA1_Update(&hashCtx, data.bytes, (CC_LONG)data.length); 132 | 133 | if (data.length == 0) { 134 | break; 135 | } 136 | } 137 | } 138 | [fp closeFile]; 139 | 140 | uint8_t buffer[CC_SHA1_DIGEST_LENGTH]; 141 | CC_SHA1_Final(buffer, &hashCtx); 142 | 143 | return [self stringFromBytes:buffer length:CC_SHA1_DIGEST_LENGTH]; 144 | } 145 | 146 | - (NSString *)fileSHA256Hash { 147 | NSFileHandle *fp = [NSFileHandle fileHandleForReadingAtPath:self]; 148 | if (fp == nil) { 149 | return nil; 150 | } 151 | 152 | CC_SHA256_CTX hashCtx; 153 | CC_SHA256_Init(&hashCtx); 154 | 155 | while (YES) { 156 | @autoreleasepool { 157 | NSData *data = [fp readDataOfLength:FileHashDefaultChunkSizeForReadingData]; 158 | 159 | CC_SHA256_Update(&hashCtx, data.bytes, (CC_LONG)data.length); 160 | 161 | if (data.length == 0) { 162 | break; 163 | } 164 | } 165 | } 166 | [fp closeFile]; 167 | 168 | uint8_t buffer[CC_SHA256_DIGEST_LENGTH]; 169 | CC_SHA256_Final(buffer, &hashCtx); 170 | 171 | return [self stringFromBytes:buffer length:CC_SHA256_DIGEST_LENGTH]; 172 | } 173 | 174 | - (NSString *)fileSHA512Hash { 175 | NSFileHandle *fp = [NSFileHandle fileHandleForReadingAtPath:self]; 176 | if (fp == nil) { 177 | return nil; 178 | } 179 | 180 | CC_SHA512_CTX hashCtx; 181 | CC_SHA512_Init(&hashCtx); 182 | 183 | while (YES) { 184 | @autoreleasepool { 185 | NSData *data = [fp readDataOfLength:FileHashDefaultChunkSizeForReadingData]; 186 | 187 | CC_SHA512_Update(&hashCtx, data.bytes, (CC_LONG)data.length); 188 | 189 | if (data.length == 0) { 190 | break; 191 | } 192 | } 193 | } 194 | [fp closeFile]; 195 | 196 | uint8_t buffer[CC_SHA512_DIGEST_LENGTH]; 197 | CC_SHA512_Final(buffer, &hashCtx); 198 | 199 | return [self stringFromBytes:buffer length:CC_SHA512_DIGEST_LENGTH]; 200 | } 201 | 202 | #pragma mark - 助手方法 203 | /** 204 | * 返回二进制 Bytes 流的字符串表示形式 205 | * 206 | * @param bytes 二进制 Bytes 数组 207 | * @param length 数组长度 208 | * 209 | * @return 字符串表示形式 210 | */ 211 | - (NSString *)stringFromBytes:(uint8_t *)bytes length:(int)length { 212 | NSMutableString *strM = [NSMutableString string]; 213 | 214 | for (int i = 0; i < length; i++) { 215 | [strM appendFormat:@"%02x", bytes[i]]; 216 | } 217 | 218 | return [strM copy]; 219 | } 220 | 221 | @end 222 | -------------------------------------------------------------------------------- /08-动态密码(时间戳密码)/08-动态密码(时间戳密码)/Security/NSString+Hash.m: -------------------------------------------------------------------------------- 1 | // 01-数据安全 2 | 3 | #import "NSString+Hash.h" 4 | #import 5 | 6 | @implementation NSString (Hash) 7 | 8 | #pragma mark - 散列函数 9 | - (NSString *)md5String { 10 | const char *str = self.UTF8String; 11 | uint8_t buffer[CC_MD5_DIGEST_LENGTH]; 12 | 13 | CC_MD5(str, (CC_LONG)strlen(str), buffer); 14 | 15 | return [self stringFromBytes:buffer length:CC_MD5_DIGEST_LENGTH]; 16 | } 17 | 18 | - (NSString *)sha1String { 19 | const char *str = self.UTF8String; 20 | uint8_t buffer[CC_SHA1_DIGEST_LENGTH]; 21 | 22 | CC_SHA1(str, (CC_LONG)strlen(str), buffer); 23 | 24 | return [self stringFromBytes:buffer length:CC_SHA1_DIGEST_LENGTH]; 25 | } 26 | 27 | - (NSString *)sha256String { 28 | const char *str = self.UTF8String; 29 | uint8_t buffer[CC_SHA256_DIGEST_LENGTH]; 30 | 31 | CC_SHA256(str, (CC_LONG)strlen(str), buffer); 32 | 33 | return [self stringFromBytes:buffer length:CC_SHA256_DIGEST_LENGTH]; 34 | } 35 | 36 | - (NSString *)sha512String { 37 | const char *str = self.UTF8String; 38 | uint8_t buffer[CC_SHA512_DIGEST_LENGTH]; 39 | 40 | CC_SHA512(str, (CC_LONG)strlen(str), buffer); 41 | 42 | return [self stringFromBytes:buffer length:CC_SHA512_DIGEST_LENGTH]; 43 | } 44 | 45 | #pragma mark - HMAC 散列函数 46 | - (NSString *)hmacMD5StringWithKey:(NSString *)key { 47 | const char *keyData = key.UTF8String; 48 | const char *strData = self.UTF8String; 49 | uint8_t buffer[CC_MD5_DIGEST_LENGTH]; 50 | 51 | CCHmac(kCCHmacAlgMD5, keyData, strlen(keyData), strData, strlen(strData), buffer); 52 | 53 | return [self stringFromBytes:buffer length:CC_MD5_DIGEST_LENGTH]; 54 | } 55 | 56 | - (NSString *)hmacSHA1StringWithKey:(NSString *)key { 57 | const char *keyData = key.UTF8String; 58 | const char *strData = self.UTF8String; 59 | uint8_t buffer[CC_SHA1_DIGEST_LENGTH]; 60 | 61 | CCHmac(kCCHmacAlgSHA1, keyData, strlen(keyData), strData, strlen(strData), buffer); 62 | 63 | return [self stringFromBytes:buffer length:CC_SHA1_DIGEST_LENGTH]; 64 | } 65 | 66 | - (NSString *)hmacSHA256StringWithKey:(NSString *)key { 67 | const char *keyData = key.UTF8String; 68 | const char *strData = self.UTF8String; 69 | uint8_t buffer[CC_SHA256_DIGEST_LENGTH]; 70 | 71 | CCHmac(kCCHmacAlgSHA256, keyData, strlen(keyData), strData, strlen(strData), buffer); 72 | 73 | return [self stringFromBytes:buffer length:CC_SHA256_DIGEST_LENGTH]; 74 | } 75 | 76 | - (NSString *)hmacSHA512StringWithKey:(NSString *)key { 77 | const char *keyData = key.UTF8String; 78 | const char *strData = self.UTF8String; 79 | uint8_t buffer[CC_SHA512_DIGEST_LENGTH]; 80 | 81 | CCHmac(kCCHmacAlgSHA512, keyData, strlen(keyData), strData, strlen(strData), buffer); 82 | 83 | return [self stringFromBytes:buffer length:CC_SHA512_DIGEST_LENGTH]; 84 | } 85 | 86 | #pragma mark - 文件散列函数 87 | 88 | #define FileHashDefaultChunkSizeForReadingData 4096 89 | 90 | - (NSString *)fileMD5Hash { 91 | NSFileHandle *fp = [NSFileHandle fileHandleForReadingAtPath:self]; 92 | if (fp == nil) { 93 | return nil; 94 | } 95 | 96 | CC_MD5_CTX hashCtx; 97 | CC_MD5_Init(&hashCtx); 98 | 99 | while (YES) { 100 | @autoreleasepool { 101 | NSData *data = [fp readDataOfLength:FileHashDefaultChunkSizeForReadingData]; 102 | 103 | CC_MD5_Update(&hashCtx, data.bytes, (CC_LONG)data.length); 104 | 105 | if (data.length == 0) { 106 | break; 107 | } 108 | } 109 | } 110 | [fp closeFile]; 111 | 112 | uint8_t buffer[CC_MD5_DIGEST_LENGTH]; 113 | CC_MD5_Final(buffer, &hashCtx); 114 | 115 | return [self stringFromBytes:buffer length:CC_MD5_DIGEST_LENGTH]; 116 | } 117 | 118 | - (NSString *)fileSHA1Hash { 119 | NSFileHandle *fp = [NSFileHandle fileHandleForReadingAtPath:self]; 120 | if (fp == nil) { 121 | return nil; 122 | } 123 | 124 | CC_SHA1_CTX hashCtx; 125 | CC_SHA1_Init(&hashCtx); 126 | 127 | while (YES) { 128 | @autoreleasepool { 129 | NSData *data = [fp readDataOfLength:FileHashDefaultChunkSizeForReadingData]; 130 | 131 | CC_SHA1_Update(&hashCtx, data.bytes, (CC_LONG)data.length); 132 | 133 | if (data.length == 0) { 134 | break; 135 | } 136 | } 137 | } 138 | [fp closeFile]; 139 | 140 | uint8_t buffer[CC_SHA1_DIGEST_LENGTH]; 141 | CC_SHA1_Final(buffer, &hashCtx); 142 | 143 | return [self stringFromBytes:buffer length:CC_SHA1_DIGEST_LENGTH]; 144 | } 145 | 146 | - (NSString *)fileSHA256Hash { 147 | NSFileHandle *fp = [NSFileHandle fileHandleForReadingAtPath:self]; 148 | if (fp == nil) { 149 | return nil; 150 | } 151 | 152 | CC_SHA256_CTX hashCtx; 153 | CC_SHA256_Init(&hashCtx); 154 | 155 | while (YES) { 156 | @autoreleasepool { 157 | NSData *data = [fp readDataOfLength:FileHashDefaultChunkSizeForReadingData]; 158 | 159 | CC_SHA256_Update(&hashCtx, data.bytes, (CC_LONG)data.length); 160 | 161 | if (data.length == 0) { 162 | break; 163 | } 164 | } 165 | } 166 | [fp closeFile]; 167 | 168 | uint8_t buffer[CC_SHA256_DIGEST_LENGTH]; 169 | CC_SHA256_Final(buffer, &hashCtx); 170 | 171 | return [self stringFromBytes:buffer length:CC_SHA256_DIGEST_LENGTH]; 172 | } 173 | 174 | - (NSString *)fileSHA512Hash { 175 | NSFileHandle *fp = [NSFileHandle fileHandleForReadingAtPath:self]; 176 | if (fp == nil) { 177 | return nil; 178 | } 179 | 180 | CC_SHA512_CTX hashCtx; 181 | CC_SHA512_Init(&hashCtx); 182 | 183 | while (YES) { 184 | @autoreleasepool { 185 | NSData *data = [fp readDataOfLength:FileHashDefaultChunkSizeForReadingData]; 186 | 187 | CC_SHA512_Update(&hashCtx, data.bytes, (CC_LONG)data.length); 188 | 189 | if (data.length == 0) { 190 | break; 191 | } 192 | } 193 | } 194 | [fp closeFile]; 195 | 196 | uint8_t buffer[CC_SHA512_DIGEST_LENGTH]; 197 | CC_SHA512_Final(buffer, &hashCtx); 198 | 199 | return [self stringFromBytes:buffer length:CC_SHA512_DIGEST_LENGTH]; 200 | } 201 | 202 | #pragma mark - 助手方法 203 | /** 204 | * 返回二进制 Bytes 流的字符串表示形式 205 | * 206 | * @param bytes 二进制 Bytes 数组 207 | * @param length 数组长度 208 | * 209 | * @return 字符串表示形式 210 | */ 211 | - (NSString *)stringFromBytes:(uint8_t *)bytes length:(int)length { 212 | NSMutableString *strM = [NSMutableString string]; 213 | 214 | for (int i = 0; i < length; i++) { 215 | [strM appendFormat:@"%02x", bytes[i]]; 216 | } 217 | 218 | return [strM copy]; 219 | } 220 | 221 | @end 222 | -------------------------------------------------------------------------------- /04-POST加密(保存本地数据)/04-POST加密(保存本地数据)/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | --------------------------------------------------------------------------------