一鸯隅、鑰匙串特點(diǎn):
1. 蘋果的"生態(tài)圈",從 iOS7.0.3 版本開放給開發(fā)者!
2. 功能:在Mac上能夠動(dòng)態(tài)生成復(fù)雜密碼,幫助用戶記住密碼!
3. 如果用戶訪問網(wǎng)站,記住密碼,我們還可以看到記住的密碼明文!明文記錄
4. 本身的所有接口都是 C 語言的.借助三方庫--SSKeychain
5. 采用的加密方式是 AES 加密!
6.存儲(chǔ)是明文的
二、iOS 開發(fā)注意
要打開鑰匙串服務(wù)
三、上代碼
#import "SSKeychain.h"
//登錄成功時(shí)保存 acount明文賬號(hào) pwd為明文密碼
+ (void)savePasword:(NSString*)pwdaccount:(NSString*)acount{
? //賬號(hào)用userdefault 保存
? [[NSUserDefaults standardUserDefaults] setValue:acount forKey:@"loginAccount"];
? [[NSUserDefaults standardUserDefaults] synchronize];
? //顯示所有賬號(hào)(卸載了還保存在手機(jī)中)
? //NSArray *allAccounts =? [SSKeychain allAccounts];
? if(pwd.length>0&& acount.length>0) {
? ? //打開鑰匙串服務(wù)
? ? /**
?? ? Password:明文密碼
?? ? Service:可以隨便寫晰奖,最好寫bunldID
?? ? account:用戶名
?? ? */
?? ? NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
?? ? [SSKeychainsetPassword:pwdforService:bundleIDaccount:acount];
? }
}
//獲取鑰匙串中的密碼
- (NSString *)loadUserInfo{
? NSString *account = [[NSUserDefaults standardUserDefaults] valueForKey:@"loginAccount"];
? //獲取所有的賬號(hào)
? // NSArray *allAccounts = [SSKeychain allAccounts];
? NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
? //取出賬號(hào)
? NSString*pwd = [SSKeychainpasswordForService:bundleIDaccount:account];
? returnpwd;
}