The purpose of Keychain in iOS

Source: Internet
Author: User
<span id="Label3"></p> <dl class="box_t"> <dl class="box_t"> <dd> keychain use in iOS </dd> </dl> </dl> <dl id="fontzoom" class="box_body"> <dd id="Article"> I. Using keychain to share data between applications         We can interpret keychain as a dictionary, all data is stored in Key-value form, You can add, update, get, Delete Four operations on this dictionary. For each application, keychain has two access areas, private and public areas. The private area is a sandbox, and any data stored by this program is not visible to other Programs. In order to put the stored content in the public area, you need to declare the name of the public area, the official document tube name is called "keychain Access group", the method is to create a new plist file, the name is random, the content is as follows:   " YourAppID.com.yourCompany.whatever "is The name of the public area you want to start, in addition to the whatever field can be arbitrarily set aside, the others must be truthfully filled Out. The path of this file is to be configured in Project->build Setting->code Signing entitlements, Otherwise the public area is invalid, after the configuration, must use your official certificate signature compiles only then can pass, Otherwise Xcode will frame the box to tell you that code signing has a Problem. so, Apple restricts you to share keychain data with your Company's products, and other companies won't be able to access your Company's products Keychain.   Save private information iOS Keychain service provides a secure way to save private information (passwords, serial numbers, certificates, etc.), each iOS program has a separate keychain Storage. Compared to nsuserdefaults, file preservation and other general way, keychain save more secure, and Keychain saved information will not be deleted because the app is lost, so after reloading the app, keychain data can also be Used.   Using keychain in the application, we need to import security.framework, Keychain operation interface declaration in the header file SECITEM.H. Directly using the SecItem.h method operation keychain, need to write code is more complex, in order to alleviate the development of our programmers, we can use some of the already packaged tool classes, below I will briefly introduce the following I used two tools class: Keychainitemwrapper and Sfhfkeychainu Tils.   (a) Keychainitemwrapper is Apple's official example "GEnerickeychain "in an access to keychain common operation of the package class, on the official web download Generickeychain project, only need to" KeychainItemWrapper.h "and" KEYCHAINITEMWRAPPER.M "copy to our project and import the Security.framework. Keychainitemwrapper usage:  /** Initializes a keychainitemwrapper */keychainitemwrapper *wrapper that saves the user account = [[ Keychainitemwrapper alloc] initwithidentifier:@ "account number"                 &N Bsp                          ,         &NB Sp              accessgroup:@ "YOUR_APP_ID_HERE.com.yourcompany.AppIdentifier"];   //save account [wrapper setobject:@ "< account >" forkey: (id) ksecattraccount];     //save password [wrapper setobject:@ "< account password >" forkey: (id) ksecvaluedata];     //remove account password from keychain nsstring *password = [wrapper objectforkey: (id) ksecvaluedata];       //empty Settings [wrapper resetkeychainitem]; method "-(void) setobject: (id) inobject forkey: (id) key;" In the "forkey" parameter.The value should be the key that is defined in the file "SecItem.h" inside the security.framework, and the key program will crash with other strings!    (b) Sfhfkeychainutils provides a secure tool for storing passwords in IOS keychain  https://github.com/ldandersen/scifihifi-iphone /tree/master/security 1, introduce Security.framework Framework.  2, Introduction Header file: sfhkeychainutils.h. 3, save password:  [sfhfkeychainutils storeusername:@ "dd" andpassword:@ "aa" Forservicename:service_name updateexisting:1 error:nil]; [sfhfkeychainutils deleteItemForUsername:@ "dd" Andservicename:service_name error:nil]; 4, take password:  nsstring *password =  [sfhfkeychainutils getpasswordforusername:@ "dd" Andservicename:service_name error:nil]; </dd> </dl><p><p> The purpose of keychain in iOS </p> </p></span>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.