美文网首页
钥匙串加密

钥匙串加密

作者: 迷失的昨天 | 来源:发表于2016-04-07 21:07 被阅读0次

    一定要先引入第三方文件#import "KeychainItemWrapper.h"

    - (void)viewDidLoad {

    [super viewDidLoad];

    //1 : 创建一个钥匙串对象

    //参数1 : 表示这个钥匙串对象的标识符

    //参数2 : 分组 一般为nil;

    KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"MyItemWrapper" accessGroup:nil];

    //钥匙串是类似于字典存储的,在存储的时候,必须使用系统提供的俩个key值,其他的存不进去

    id kUserName = (__bridge id)kSecAttrAccount;

    id kPassWord = (__bridge id)kSecValueData;

    // 存入到钥匙串里面

    [wrapper setObject:@"123" forKey:kUserName];

    [wrapper setObject:@"abc" forKey:kPassWord];

    //这里已经保存完成了

    #pragma make --------- 获取钥匙串的数据 --------

    KeychainItemWrapper *newwrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"MyItemWrapper" accessGroup:nil];

    NSString *newName = [newwrapper objectForKey:kUserName];

    NSString *newWord = [newwrapper objectForKey:kPassWord];

    NSLog(@"userNane ===== %@, passWord ===== %@", newName, newWord);

    }

    相关文章

      网友评论

          本文标题:钥匙串加密

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