我想存储已登录我的iOS应用程序的用户的RSA密钥对,但是这样可以使密钥与其他用户区分开。我为此编写了代码,但是每次登录后它都会覆盖密钥。
代码如下:
+(BOOL)storeRSAComponentInKeychain:(NSData*)keyPairComponent keyAttrClass:(CFStringRef)keyAttrClass {
NSMutableDictionary* keychainItem = [NSMutableDictionary dictionary];
keychainItem[(__bridge id)kSecClass] = (__bridge id)kSecClassKey;
keychainItem[(__bridge id)kSecAttrKeyType] = (__bridge id)kSecAttrKeyTypeRSA;
keychainItem[(__bridge id)kSecAttrKeyClass] = (__bridge id)keyAttrClass;
keychainItem[(__bridge id)kSecAttrAccessible] = (__bridge id)kSecAttrAccessibleWhenUnlocked;
keychainItem[(__bridge id)kSecAttrIsPermanent] = @YES;
keychainItem[(__bridge id)kSecReturnPersistentRef] = @YES;
keychainItem[(__bridge id)kSecAttrApplicationTag] = [self secItemTagDataForKAttrClass:keyAttrClass];
keychainItem[(__bridge id)kSecValueData] = keyPairComponent;
return [self storeItemInKeychain:keychainItem];
}
无论如何,我可以动态生成用于保存密钥的属性,例如RSA_username,并将相应的密钥保存在钥匙串的该属性中,以便我可以轻松获取所需用户的密钥。或任何其他方式来实现它。请帮助,我是iOS开发的新手。