加密和解密

通过钥匙串对用户信息的存储,访问和删除

2020-04-16  本文已影响0人  Andy_Livings

存储账户密码

使用第三方SFHFKeychainUtils
引入头文件

    #import <SFHFKeychainUtils.h>
/// 存储账户密码
+ (void)encryptionManagerKeychainUtilsStoreUsername:(NSString *)userName andPassword:(NSString *)password forServiceName:(NSString *)serviceName updateExisting:(BOOL)updateExisting {

    [SFHFKeychainUtils storeUsername:userName andPassword:password forServiceName:serviceName updateExisting:YES  error:nil];
}

根据用户名取出密码

/// 根据用户名取出密码
+ (NSString *)encryptionManagerKeychainUtilsGetPasswordForUsername:(NSString *)userName andServiceName:(NSString *)serviceName {
   
    //    NSString  *passWordOld = [SFHFKeychainUtils getPasswordForUsernameOld:userName andServiceName:serviceName error:nil];
    
    NSString  *passWord = [SFHFKeychainUtils getPasswordForUsernameV2:userName andServiceName:serviceName error:nil];
    
    return passWord;
}

删除用户

/// 删除用户
+ (void)encryptionManagerKeychainUtilsDeleteItemForUsername:(NSString *)userName andServiceName:(NSString *)serviceName withAccessible:(BOOL)accessible {
    
    [SFHFKeychainUtils deleteItemForUsername:userName andServiceName:serviceName error:nil withAccessible:accessible];
}

Demo

上一篇 下一篇

猜你喜欢

热点阅读