美文网首页加密和解密
通过钥匙串对用户信息的存储,访问和删除

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

作者: Andy_Livings | 来源:发表于2020-04-16 18:46 被阅读0次

    存储账户密码

    使用第三方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

    相关文章

      网友评论

        本文标题:通过钥匙串对用户信息的存储,访问和删除

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