https://github.com/dagronf/dsfsimplekeychainpassword
Simple Swift wrapper around keychain generic password handling
https://github.com/dagronf/dsfsimplekeychainpassword
keychain macos swift
Last synced: 10 months ago
JSON representation
Simple Swift wrapper around keychain generic password handling
- Host: GitHub
- URL: https://github.com/dagronf/dsfsimplekeychainpassword
- Owner: dagronf
- License: mit
- Created: 2018-12-08T23:40:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-08T23:40:53.000Z (over 7 years ago)
- Last Synced: 2025-04-04T21:45:54.966Z (about 1 year ago)
- Topics: keychain, macos, swift
- Language: Swift
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DSFSimpleKeychain
A simple Swift wrapper around keychain functions for storing and retrieving keychain 'generic passwords'
## Create a keychain password
let service = DSFSimpleKeychain.Service("My Application Data")
let addAccountStatus = service.add(accountNamed: "AWSLoginID", password: "")
if case .success(let addAccountInfo) = addAccountStatus
{
print("Created account: \(addAccountInfo.account)")
}
else
{
print("Unable to create password")
return
}
### Command line equivalent
$ security add-generic-password -s "My Application Data" -a "AWSLoginID" -w ""
## List the stored passwords for a service
let service = DSFSimpleKeychain.Service("My Application Data")
let allAccounts = service.accounts()
if case .success(let accounts) = allAccounts
{
print("Found accounts: \(accounts)")
}
else
{
print("Unable to retrieve account information")
}
## Retrieve a keychain password
let service = DSFSimpleKeychain.Service("My Application Data")
let retrieveStatus = service.retrieve(accountNamed: "AWSLoginID")
guard case .success(let accountInfo) = retrieveStatus else
{
print("Unable to retrieve password")
return
}
print("Password is \(accountInfo.password)")
### Command line equivalent
$ security find-generic-password -s "My Application Data" -a "AWSLoginID" -w
## Delete a password from the keychain
let service = DSFSimpleKeychain.Service("My Application Data")
let deleteResult = service.delete(accountNamed: "AWSLoginID")
if deleteResult != DSFSimpleKeychain.Status.success
{
print("Unable to delete password")
return
}
### Command line equivalent
$ security delete-generic-password -s "My Application Data" -a "AWSLoginID"