{"id":15050773,"url":"https://github.com/itenfay/dyfkeychain","last_synced_at":"2025-08-24T13:15:43.894Z","repository":{"id":56908116,"uuid":"229783551","full_name":"itenfay/DYFKeychain","owner":"itenfay","description":"This library is used to store text and data in Keychain securely for iOS, OS X, tvOS and watchOS.","archived":false,"fork":false,"pushed_at":"2024-06-22T17:18:57.000Z","size":133,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-19T16:10:59.956Z","etag":null,"topics":["cocoapods","icloud","ios","keychain","keychain-access","keychain-api","keychain-management","keychain-services","keychain-sharing","keychain-synchronization","keychain-wrapper","keychainwrapper","objc","objective-c","security","security-framework"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itenfay.png","metadata":{"files":{"readme":"README-en.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-23T16:04:02.000Z","updated_at":"2024-06-22T17:17:19.000Z","dependencies_parsed_at":"2024-06-02T10:13:57.271Z","dependency_job_id":"e7820a8e-79e5-49c6-9573-236decb8adf6","html_url":"https://github.com/itenfay/DYFKeychain","commit_stats":null,"previous_names":["itenfay/dyfkeychain"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/itenfay/DYFKeychain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itenfay%2FDYFKeychain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itenfay%2FDYFKeychain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itenfay%2FDYFKeychain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itenfay%2FDYFKeychain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itenfay","download_url":"https://codeload.github.com/itenfay/DYFKeychain/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itenfay%2FDYFKeychain/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271872749,"owners_count":24837151,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocoapods","icloud","ios","keychain","keychain-access","keychain-api","keychain-management","keychain-services","keychain-sharing","keychain-synchronization","keychain-wrapper","keychainwrapper","objc","objective-c","security","security-framework"],"created_at":"2024-09-24T21:29:18.755Z","updated_at":"2025-08-24T13:15:43.831Z","avatar_url":"https://github.com/itenfay.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"English Vision | [中文版](README.md)\n\n\n## DYFKeychain\n\nThis is used to store text and data in the Keychain([Swift Version](https://github.com/itenfay/DYFSwiftKeychain)). As you probably noticed Apple's keychain API is a bit verbose. This library was designed to provide shorter syntax for accomplishing a simple task: reading/writing text values for specified keys:\n\n```objc\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\n[keychain add:@\"User Account Passcode\" forKey:@\"kUserAccPasscode\"];\nNSString *p = [keychain get:@\"kUserAccPasscode\"];\n```\n\nThe Keychain library includes the following features:\n\n- Get, set and delete string, boolean and Data Keychain items.\n- Specify item access security level.\n- Synchronize items through iCloud.\n- Share Keychain items with other apps.\n\n[![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](LICENSE)\u0026nbsp;\n[![CocoaPods Version](http://img.shields.io/cocoapods/v/DYFKeychain.svg?style=flat)](http://cocoapods.org/pods/DYFKeychain)\u0026nbsp;\n![CocoaPods Platform](http://img.shields.io/cocoapods/p/DYFKeychain.svg?style=flat)\u0026nbsp;\n\n\n## Group (ID:614799921)\n\n\u003cdiv align=left\u003e\n\u0026emsp; \u003cimg src=\"https://github.com/itenfay/DYFKeychain/raw/master/images/g614799921.jpg\" width=\"30%\" /\u003e\n\u003c/div\u003e\n\n\n## Installation\n\nUsing [CocoaPods](https://cocoapods.org):\n\n``` \npod 'DYFKeychain'\n```\n\nOr\n\n```\npod 'DYFKeychain', '~\u003e 1.2.0'\n```\n\nOr manually add the files from the [Keychain](https://github.com/itenfay/DYFKeychain/tree/master/Keychain) directory.\n\n\n## What's Keychain?\n\nKeychain is a secure storage. You can store all kind of sensitive data in it: user passwords, credit card numbers, secret tokens etc. Once stored in Keychain this information is only available to your app, other apps can't see it. Besides that, operating system makes sure this information is kept and processed securely. For example, text stored in Keychain can not be extracted from iPhone backup or from its file system. Apple recommends storing only small amount of data in the Keychain. If you need to secure something big you can encrypt it manually, save to a file and store the key in the Keychain.\n\n\n## Usage\n\nAdd `#import \"DYFKeychain.h\"` to your source code.\n\n### String values\n\n```objc\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\n[keychain add:@\"User Account Passcode\" forKey:@\"kUserAccPasscode\"];\nNSString *s = [keychain get:@\"kUserAccPasscode\"];\n```\n\n### Data values\n\n```objc\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\n[keychain addData:data forKey:@\"kCommSecureCode\"];\nNSData *data = [keychain getData:@\"kCommSecureCode\"];\n```\n\n### Boolean values\n\n```objc\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\n[keychain addBool:YES forKey:@\"kFirstInstalledAndLaunched\"];\nBOOL ret = [keychain getBool:@\"kFirstInstalledAndLaunched\"];\n```\n\n### Removing keys from Keychain\n\n```objc\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\n[keychain delete:@\"kFirstInstalledAndLaunched\"]; // Remove single key.\n[keychain clear]; // Delete everything from app's Keychain. Does not work on macOS.\n```\n\n\n## Advanced options\n\n### Keychain item access\n\nUse `options` parameter to specify the security level of the keychain storage. By default the `DYFKeychainAccessOptionsAccessibleWhenUnlocked` option is used. It is one of the most restrictive options and provides good data protection.\n\n```objc\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\n[keychain add:@\"xxx\" forKey:@\"Key1\" options:DYFKeychainAccessOptionsAccessibleWhenUnlocked];\n```\n\nYou can use `DYFKeychainAccessOptionsAccessibleAfterFirstUnlock` if you need your app to access the keychain item while in the background. Note that it is less secure than the `DYFKeychainAccessOptionsAccessibleAfterFirstUnlock` option.\n\nSee the list of all available [access options](https://github.com/itenfay/DYFKeychain/blob/master/Keychain/DYFKeychain.h).\n\n\n### Synchronizing keychain items with other devices\n\nSet `synchronizable` property to `YES` to enable keychain items synchronization across user's multiple devices. The synchronization will work for users who have the \"Keychain\" enabled in the iCloud settings on their devices.\n\nSetting `synchronizable` property to `YES` will add the item to other devices with the `add` method and obtain synchronizable items with the `get` command. Deleting a synchronizable item will remove it from all devices.\n\nNote that you do not need to enable iCloud or Keychain Sharing capabilities in your app's target for this feature to work.\n\n```objc\n// The first device\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\nkeychain.synchronizable = YES;\n[keychain add:@\"See you tomorrow!\" forKey:@\"key12\"];\n\n// The second device\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\nkeychain.synchronizable = YES;\n[keychain get:@\"key12\"];\n```\n\nWe could not get the Keychain synchronization work on macOS.\n\n\n### Sharing keychain items with other apps\n\nIn order to share keychain items between apps on the same device they need to have common *Keychain Groups* registered in *Capabilities \u003e Keychain Sharing* settings. There are online tutorials shows how to set it up.\n\nUse `accessGroup` property to access shared keychain items. In the following example we specify an access group \"9ZU3R2F3D4.com.omg.myapp.KeychainGroup\" that will be used to set, get and delete an item \"key1\".\n\n```objc\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\nkeychain.accessGroup = @\"9ZU3R2F3D4.com.omg.myapp.KeychainGroup\" // Use your own access group.\n\n[keychain add:@\"hello world!\" forKey:@\"key12\"];\n[keychain get:@\"key12\"];\n[keychain delete:@\"key12\"];\n[keychain clear];\n```\n\n*Note*: there is no way of sharing a keychain item between the watchOS 2.0 and its paired device: https://forums.developer.apple.com/thread/5938\n\n\n### Check if operation was successful\n\nYou can verify if `add`, `delete` and `clear` methods finished successfully by checking their return values. Those methods return `YES` on success and `NO` on error.\n\n```objc\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\n\nif ([keychain add:@\"xxx\" forKey:@\"key1\"]) {\n  // Keychain item is saved successfully\n} else {\n  // Report error\n}\n```\n\nTo get a specific failure reason use the `osStatus` property containing result code for the last operation. See [Keychain Result Codes](https://developer.apple.com/documentation/security/1542001-security_framework_result_codes).\n\n```objc\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\n\n[keychain add:@\"xxx\" forKey:@\"key1\"];\nif (keychain.osStatus != errSecSuccess) { /* Report error */ }\n```\n\n\n### Returning data as reference\n\nUse the `asReference: YES` parameter to return the data as reference, which is needed for [NEVPNProtocol](https://developer.apple.com/documentation/networkextension/nevpnprotocol).\n\n```objc\nDYFKeychain *keychain = [DYFKeychain defaultKeychain];\n\n[keychain addData:data forKey:@\"key1\"];\n[keychain getData:@\"key1\" asReference:YES];\n```\n\n\n## Demo\n\n`DYFKeychain` is learned how to use under this [Demo](https://github.com/itenfay/DYFStoreKit/blob/master/Classes/DYFStoreKeychainPersistence.m).\n\n\n## Feedback is welcome\n\nIf you notice any issue to create an issue. I will be happy to help you.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitenfay%2Fdyfkeychain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitenfay%2Fdyfkeychain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitenfay%2Fdyfkeychain/lists"}