使用KeyChainItemWrapper在KeyChain中存储密钥 [英] Storing keys in KeyChain with KeyChainItemWrapper

查看:139
本文介绍了使用KeyChainItemWrapper在KeyChain中存储密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apple的示例代码提供的KeyChainItemWrapper类将身份验证令牌保存到钥匙串。

I'm using KeyChainItemWrapper class, provided by Apple's Sample Code to save the authentication token to the keychain.

KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier"JetTaxiApp_AuthToken" accessGroup:nil];  

但是当我试图将值设置为keychain时,会引发奇怪的异常

But when I'm trying to set the value to keychain, an odd exception is raised

[_authenticationTokenKeychain setObject:authenticationToken forKey: @"auth_token"];




由于未捕获的异常而终止应用
'NSInternalInconsistencyException',原因:'无法添加钥匙串
项。'

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'

钥匙串尚不存在(目前这个电话)
什么可能导致这个例外?

The keychain doesn't exist yet (at the moment of this call) What can cause this exception?

推荐答案

你需要使用标准键,所以这里你的 @auth_token不正确。

You need to use standard keys, so here your @"auth_token" is incorrect.


可用于此目的的密钥每个键的可能值都列在Keychain Services Constants部分。

The keys that can be used for this purpose and the possible values for each key are listed in the "Keychain Services Constants" section.

source,包含有效常量列表:< a href =http://developer.apple.com/library/ios/#documentation/Security/Reference/keychainservices/Reference/reference.html\"rel =noreferrer>钥匙串服务参考

source, with list of valid constants: Keychain Services Reference

例如,您可以使用:


[_ authenticationTok enKeychain setObject:authenticationToken forKey:(__ bridge NSString *)kSecValueData];

[_authenticationTokenKeychain setObject:authenticationToken forKey: (__bridge NSString *)kSecValueData];

这篇关于使用KeyChainItemWrapper在KeyChain中存储密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆