Skip to content

Commit fd7e8ef

Browse files
committed
Update README.md
1 parent eb36bb9 commit fd7e8ef

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

README.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ let password: String? = try keychain.retrieve(
9292
For example, if you need to store distinct ports credentials for the same user working on the same server, you might further characterize the query by specifying protection space.
9393

9494
```swift
95-
let space1 = WebProtectionSpace(host: "https://example.com", port: 443)
95+
let space1 = WebProtectionSpace(host: "example.com", port: 443)
9696
try keychain.store(password1, query: .credential(for: user, space: space1))
9797

98-
let space2 = WebProtectionSpace(host: "https://example.com", port: 8443)
98+
let space2 = WebProtectionSpace(host: "example.com", port: 8443)
9999
try keychain.store(password2, query: .credential(for: user, space: space2))
100100
```
101101

102-
#### Get Attribute
102+
#### Get Attributes
103103

104104
```swift
105105
if let info = try keychain.info(for: .credential(for: "OpenAI")) {
@@ -156,6 +156,30 @@ SecItemQuery<SecCertificate> // kSecClassSecCertificate
156156
SecItemQuery<SecIdentity> // kSecClassSecIdentity
157157
```
158158

159+
#### CryptoKit
160+
161+
```swift
162+
// Store private key
163+
let privateKey = P256.KeyAgreement.PrivateKey()
164+
try Keychain.default.store(privateKey, query: .privateKey(tag: "Alice"))
165+
166+
// Retrieve private key (+ public key)
167+
let privateKey: P256.KeyAgreement.PrivateKey? = try? Keychain.default.retrieve(.privateKey(tag: "Alice"))
168+
let publicKey = privateKey.publicKey
169+
```
170+
171+
#### Get Data & Persistent Reference
172+
173+
```swift
174+
let value = try keychain.retrieve([.data, .persistentReference], query: .credential(for: "OpenAI"))
175+
if case let .dictionary(info) = value {
176+
// Data
177+
info.data
178+
// Persistent Reference
179+
info.persistentReference
180+
}
181+
```
182+
159183
#### Debug
160184

161185
```swift
@@ -256,10 +280,8 @@ if success {
256280
> [SharedWebCredentials API](https://developer.apple.com/documentation/security/shared_web_credentials) makes it possible to share credentials with the website counterpart. For example, a user may log in to a website in Safari and save credentials to the iCloud Keychain. Later, the user may run an app from the same developer, and instead of asking the user to reenter a username and password, it could access the existing credentials. The user can create new accounts, update passwords, or delete account from within the app. These changes should be saved from the app to be used by Safari.
257281
258282
```swift
259-
let credential = SharedWebCredential("https://example.com", account: "username")
260-
261-
// Store
262-
credential.store(password) { result in
283+
/ Store
284+
SharedWebCredential.store("https://example.com", account: "username", password: "secret") { result in
263285
switch result {
264286
case .failure(let error):
265287
// Handle error
@@ -269,14 +291,14 @@ credential.store(password) { result in
269291
}
270292

271293
// Remove
272-
credential.remove(completion: { result in
294+
SharedWebCredential.remove("https://example.com", account: "username") { result in
273295
switch result {
274296
case .failure(let error):
275297
// Handle error
276298
case .success:
277299
// Handle success
278300
}
279-
})
301+
}
280302

281303
// Retrieve
282304
// - Use `ASAuthorizationController` to make an `ASAuthorizationPasswordRequest`.
@@ -305,7 +327,7 @@ To add support for custom types, you can extend them by conforming to the follow
305327
// Store as Data (GenericPassword, InternetPassword)
306328
extension CustomType: SecDataConvertible {}
307329

308-
// Store as Key (SecKey)
330+
// Store as x8.Key (SecKey)
309331
extension CustomType: SecKeyConvertible {}
310332

311333
// Store as Certificate (X.509)

0 commit comments

Comments
 (0)