iOS在钥匙串中保存多个密码 [英] iOS save multiple passwords in keychain

查看:486
本文介绍了iOS在钥匙串中保存多个密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的钥匙串中保存两个密码(一个app pin和一个后端pin),我想知道这应该如何工作。

我正在使用KeychainItemWrapper与不同的标识符。

I want to save two passwords (one app pin and one backend pin) in my keychain and am wondering how this should work.
I am using the KeychainItemWrapper with to different identifiers.

KeychainItemWrapper *kcw1 = [[KeychainItemWrapper alloc] initWithIdentifier:id1 accessGroup:nil];
KeychainItemWrapper *kcw2 = [[KeychainItemWrapper alloc] initWithIdentifier:id2 accessGroup:nil];

我正在使用其中任何一个保存并重新启动应用程序或后端引脚。

and I am using either one to save and retrive the app or the backend pin.

我使用:

[self.kcw1 setObject:aVerifyCode forKey:(__bridge id) kSecValueData]
[self.kcw2 setObject:aAppPin forKey:(__bridge id) kSecValueData]

但它不起作用 - 结果是-25299 - 指定的项目已经存在于钥匙串中

But it doesn't work - result is -25299 - The specified item already exists in the keychain

那么如何在我的钥匙串中保存多个密码?

So how can I save multiple passwords in my keychain?

推荐答案

好吧我想我知道问题是什么!
KeychainItemWrapper使用kSecAttrGeneric的标识符。

但这不是区分条目的标识符。如果你想保存两个账户或两个密码

Okay I think I know what the problem is! KeychainItemWrapper uses the identifier for the kSecAttrGeneric.
But this is not the one to distinguish entries. If you want to save two accounts or two passwords in


kSecValueData

kSecValueData

这将导致重复entires的恐怖(-25299)。

原因是,苹果钥匙串api使用

this will result in an arror (-25299) for duplicate entires.
The reason is, that the apple keychain api uses


kSecAttrAccount

kSecAttrAccount


kSecAttrService

kSecAttrService

来区分条目。

所以你可以修改keychainItemWraper如果你希望如此主题中所示

这篇关于iOS在钥匙串中保存多个密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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