iOS钥匙串偶尔会返回空字符串 [英] iOS Keychain occasionally return empty string
问题描述
我为银行编写了非常安全的应用程序,并将私钥保存在钥匙串中. 我使用以下代码保留私钥:
I write very secure application (for Bank) and I keep the private key in the Keychain. I keep the Private key using the following code:
+(void)savePrivatekey:(NSString *)Key
{
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"pKey" accessGroup:nil];
[keychain setObject:Key forKey:(id)kSecValueData];
[keychain release];
}
,并使用以下代码获取私钥:
and for get the private key using the following code:
+(NSString *)privateKey
{
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"pKey"accessGroup:nil];
NSString *privateKey = [keychain objectForKey:(id)kSecValueData];
[keychain release];
return privateKey;
}
出于安全原因,我不将私钥保存在本地变量中. 因为每次对服务器的调用都需要我调用的私钥才能起作用 "GetPrivateKey"很多次. 也许这就是为什么有时我会从钥匙串空字符串中得到的原因. 我想不出为什么会发生这种情况. 我注意到在大多数情况下,当应用程序从后台返回时会发生这种情况,但不仅如此... 谢谢...
i don't save the private key in local variable from security reasons. because every call to server I need the private key i call to to function "GetPrivateKey" a lot of times. Maybe that's why sometimes i get from the keychain empty string. i can't think of why this might happen. I noticed that in most cases this happens when the application return from background but no only... thanks...
我向Apple的工程师开了票,他们回应了我:
I opened ticket at Apple's engineers and they responded to me:
最初创建钥匙串项时是否设置了kSecAttrAccessible属性?
Are you setting the kSecAttrAccessible attribute when you create the keychain item initially?
我总是创建相同形状的钥匙串: KeychainItemWrapper * keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"pKey" accessGroup:nil];
I always create the same shape keychain: KeychainItemWrapper * keychain = [[KeychainItemWrapper alloc] initWithIdentifier: @ "pKey" accessGroup: nil];
有人知道他们的意图吗? 谢谢...
Does anyone know what their intent? thanks...
推荐答案
一段时间前,我回答了自己的问题.我不确定这是否是您的确切问题,因为您的代码看起来/工作正常.因此,关于您的钥匙串访问,我想这有点不同.这可能会或可能不会有帮助,但可能会引导您朝正确的方向前进.
I answered my own question a while back regarding this. I'm not sure if this is your exact problem as your code seems to look/work fine. So regarding your keychain access, I'm guessing it is a bit different. This may or may not help, but might steer you in the right direction.
这篇关于iOS钥匙串偶尔会返回空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!