数据加密之钥匙串加密

- (void)viewDidLoad {
    [super viewDidLoad];
    // 创建钥匙串的对象
    //参数1:标识,用于识别(--识别我们待会会加密的内容)
    //参数2:组一般为nil
    KeychainItemWrapper *keychainItem =[[KeychainItemWrapper alloc]initWithIdentifier:@"myItemWrapper" accessGroup:nil];
    //用于加密用户名和密码:
    //系统提供的键值对中的键,非系统的键没有办法添加到字典中
    //__bridge id 桥接 做类型转换
    id kUserName = (__bridge id)kSecAttrAccount;
    
    id kUserpassWord = (__bridge id)kSecValueData;
    
    
    [keychainItem setObject:@"titlebaby" forKey:kUserName];
    [keychainItem setObject:@"345678" forKey:kUserpassWord];
    
    NSLog(@"keychainItem=%@",keychainItem);
    
    
    
    //重keychain中获取数据
    NSString *userName = [keychainItem objectForKey:kUserName];
    //密码
    NSString *passWord = [keychainItem objectForKey:kUserpassWord];
    NSLog(@"username=%@, passWork=%@",userName,passWord);

你可能感兴趣的:(数据加密之钥匙串加密)