ios – Keychain – 安全数据存储
我正在开发一个带钥匙串实现的应用程序.我能够创造&将数据保存到钥匙串中.我正在使用Apple提供的
Keychain Wrapper classes.
根据要求,我必须在KeyChain中实现最好的安全性(安全团队指出了失误,例如它在Jail-broken设备上的可访问性). 有人可以指点我吗? 解决方法
我还在应用程序中实现了keychain long返回使用你引用的相同Wrapper,当然还有很多修改.
基本上Keychain非常安全.根据Apple的说法,它是一个加密容器,可以保存多个应用程序的安全信息,这意味着当钥匙串被锁定时,没有人可以访问其受保护的内容. 在iOS中,只有创建钥匙串的应用程序才能访问它. 但是从iOS 4.xx开始,它只是磁盘缓存(不知道为什么),因此总是创建一个 Sqlite DB可以在root或Jail-broken设备上被黑客攻击. 保护钥匙串 1在添加或添加安全关键字“kSecAttrAccessibleWhenUnlockedThisDeviceOnly”时 就像是 :- - (void)writeToKeychain { NSDictionary *attributes = NULL; NSMutableDictionary *updateItem = NULL; OSStatus result; if (SecItemCopyMatching((CFDictionaryRef)genericPasswordQuery,(CFTypeRef *)&attributes) == noErr) { updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes]; [updateItem setObject:[genericPasswordQuery objectForKey:(id)kSecClass] forKey:(id)kSecClass]; NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainItemData]; [tempCheck removeObjectForKey:(id)kSecClass]; #if TARGET_IPHONE_SIMULATOR [tempCheck removeObjectForKey:(id)kSecAttrAccessGroup]; #endif [updateItem setObject:(id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly forKey:(id)kSecAttrAccessible]; result = SecItemUpdate((CFDictionaryRef)updateItem,(CFDictionaryRef)tempCheck); NSAssert( result == noErr,@"Couldn't update the Keychain Item." ); CFRelease(attributes); } else { [keychainItemData setObject:(id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly forKey:(id)kSecAttrAccessible]; result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData],NULL); NSAssert( result == noErr,@"Couldn't add the Keychain Item." ); } } 2在添加到Keychain之前加密数据.我使用AES-128加密. 注意: – 钥匙串数据存储在iPhone上的/private/var/Keychains/keychain-2.db文件中. 希望它能帮到你. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |