Logo
Pattern

Discover published sets by community

Explore tens of thousands of sets crafted by our community.

iOS Keychain Services

15

Flashcards

0/15

Still learning
StarStarStarStar

Adding an Item

StarStarStarStar

To add an item, prepare a `NSDictionary` of attributes and pass it to `SecItemAdd`. Example: `let query = [kSecClass: kSecClassGenericPassword, kSecAttrAccount: "User"]`

StarStarStarStar

Querying Items

StarStarStarStar

To find items, create a search query and use `SecItemCopyMatching`. Example: `SecItemCopyMatching(query as CFDictionary, &item)`

StarStarStarStar

Keychain Basics

StarStarStarStar

Keychain services provide secure storage for passwords, certificates, and other secrets. Example: Using `SecItemAdd` to add an item to the keychain.

StarStarStarStar

Updating Items

StarStarStarStar

Update existing items by specifying attributes to change using `SecItemUpdate`. Example: `SecItemUpdate(query as CFDictionary, attributesToUpdate as CFDictionary)`

StarStarStarStar

Deleting Items

StarStarStarStar

Items can be deleted using `SecItemDelete` and a query. Example: `SecItemDelete(query as CFDictionary)`

StarStarStarStar

Access Control

StarStarStarStar

Define how a keychain item is accessed, by using `SecAccessControlCreateWithFlags`. Example: `let access = SecAccessControlCreateWithFlags(nil, kSecAttrAccessibleWhenUnlocked, .userPresence, &error)`

StarStarStarStar

Keychain Error Handling

StarStarStarStar

Handle errors from keychain operations by checking the returned status. Example: `let status = SecItemAdd(query as CFDictionary, nil); if status != errSecSuccess { handle error }`

StarStarStarStar

Synchronizing Keychain Items

StarStarStarStar

Keychain items can be synchronized across devices using iCloud by setting `kSecAttrSynchronizable`. Example: `query[kSecAttrSynchronizable] = kSecAttrSynchronizableAny`

StarStarStarStar

Securing with Touch ID/Face ID

StarStarStarStar

Secure items with biometrics by setting `kSecAccessControlUserPresence` for an access control object. Example: `let accessControl = SecAccessControlCreateWithFlags(nil, kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly, .userPresence, nil)`

StarStarStarStar

Sharing Keychain Items

StarStarStarStar

Items can be shared between apps by using `kSecAttrAccessGroup`. Example: `query[kSecAttrAccessGroup] = "<App Identifier Prefix>.com.example.shared"`

StarStarStarStar

Accessing Internet Passwords

StarStarStarStar

For passwords related to internet accounts, use `kSecClassInternetPassword`. Example: `let query = [kSecClass: kSecClassInternetPassword, kSecAttrServer: "www.example.com"]`

StarStarStarStar

Concurrency with Keychain

StarStarStarStar

iOS Keychain API is thread-safe, allowing for concurrent access. Example: Use GCD or `OperationQueue` to access the keychain concurrently without issues.

StarStarStarStar

Persistent References

StarStarStarStar

Use persistent references to a keychain item to avoid repeatedly querying for it. Example: `let query: [String: Any] = [kSecClass: kSecClassGenericPassword, kSecReturnPersistentRef: true]`

StarStarStarStar

Retrieving Passwords

StarStarStarStar

To get a password from the keychain, set `kSecReturnData` to get data along with the item associated with `kSecClassGenericPassword`. Example: `query[kSecReturnData] = kCFBooleanTrue`

StarStarStarStar

Keychain Item Attributes

StarStarStarStar

Keychain items can have various attributes like `kSecAttrService`, `kSecAttrAccount`. Example: `let attributes = [kSecAttrService: "ExampleService", kSecAttrAccount: "ExampleAccount"]`

Know
0
Still learning
Click to flip
Know
0
Logo

© Hypatia.Tech. 2024 All rights reserved.