ios keychain 介紹

Download iOS Keychain 介紹

Post on 14-Jul-2015

315 views

Category:

Software

3 download

Embed Size (px)

TRANSCRIPT

iOS KeyChain

iOS KeyChainHappyMan2014/12/30

What is KeyChainKeychain is an encrypted container where you can store secured information like passwords, certificates, identities, etc.In iOS, each application has its own keychain.To share the data between apps, they should have the same Access Group in code signing entitlements.Accessing password-protected services using a keychain in OS X

Accessing an Internet server using iPhone Keychain Services

KeyChain iOS keychain /private/var/Keychains/keychain-2.db( keychain-access-groups ) app app keychain app app keychain app keychain keychain

APISecItemAddSecItemCopyMatchingSecItemUpdateSecItemDelete-(NSMutableDictionary *) prepareDict:(NSString *)key{ NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; [dict setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass]; NSData *encodedKey = [key dataUsingEncoding:NSUTF8StringEncoding]; [dict setObject:encodedKey forKey:(__bridge id)kSecAttrGeneric]; [dict setObject:encodedKey forKey:(__bridge id)kSecAttrAccount]; [dict setObject:service forKey:(__bridge id)kSecAttrService]; [dict setObject:(__bridge id)kSecAttrAccessibleAlwaysThisDeviceOnly forKey:(__bridge id)kSecAttrAccessible]; return dict;}-(BOOL) insert:(NSString *)key :(NSData *)data{ NSMutableDictionary *dict =[self prepareDict:key]; [dict setObject:data forKey:(__bridge id)kSecValueData]; OSStatus status = SecItemAdd((__bridge CFDictionaryRef)dict, NULL); if(errSecSuccess != status) { NSLog(@"Unable add item with key = %@ error: %d",key,(int)status); } return (status == errSecSuccess);}-(NSData*) find:(NSString *)key{ NSMutableDictionary *dict = [self prepareDict:key]; [dict setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit]; [dict setObject:(id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData]; CFTypeRef result = NULL; OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dict,&result); if(status != errSecSuccess) { NSLog(@"Unable to fetch item for key %@ with error: %d",key,(int)status); return nil; } return (__bridge NSData *)result;}-(BOOL) update:(NSString*)key :(NSData *)data{ NSMutableDictionary *dictKey =[self prepareDict:key]; NSMutableDictionary *dictUpdate =[[NSMutableDictionary alloc] init]; [dictUpdate setObject:data forKey:(__bridge id)kSecValueData]; OSStatus status = SecItemUpdate((__bridge CFDictionaryRef)dictKey, (__bridge CFDictionaryRef)dictUpdate); if(status != errSecSuccess) { NSLog(@"Unable add update with key = %@ error: %d",key,(int)status); } return (status == errSecSuccess);}-(BOOL) remove:(NSString *)key{ NSMutableDictionary *dict = [self prepareDict:key]; OSStatus status = SecItemDelete((__bridge CFDictionaryRef)dict); if(status != errSecSuccess) { NSLog(@"Unable to remove item for key %@ with error: %d",key,(int)status); } return (status == errSecSuccess);}SSKeychainhttps://github.com/soffes/sskeychainStar: 1730 (2014/12/30)SFHFKeychainUtilshttps://github.com/kamiro/SFHFKeychainUtilsStar: 60 (2014/12/30)Me: 2 projects

Demohttps://github.com/happymanx/KeyChainTest1). Initialization of the class2). How to Add an item to keychain3). Find an item in the keychain4). Update an item in the keychain5). Remove an item from keychain

iOS KeyChain Tutorialhttp://hayageek.com/ios-keychain-tutorial/Securing and Encrypting Data on iOShttp://code.tutsplus.com/tutorials/securing-and-encrypting-data-on-ios--mobile-21263Basic Security in iOS 5 Part 1http://www.raywenderlich.com/6475/basic-security-in-ios-5-tutorial-part-1Basic Security in iOS 5 Part 2http://www.raywenderlich.com/6603/basic-security-in-ios-5-tutorial-part-2

iOS Keychain: Sharing data between appshttp://shaune.com.au/ios-keychain-sharing-data-between-apps/Keychain Group Accesshttp://useyourloaf.com/blog/2010/04/03/keychain-group-access.html KeyChainhttp://wp.me/p1my2P-3S0KeyChain http://blog.csdn.net/ibcker/article/details/24839143

AppleKeychain Services Programming Guidehttps://developer.apple.com/library/mac/documentation/Security/Conceptual/keychainServConcepts/Keychain Services Referencehttps://developer.apple.com/library/mac/documentation/Security/Reference/keychainservices/#WWDC14 session 711 - Keychain and Authentication with Touch ID