File size: 1,934 Bytes
d086025 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # Keyring — Usage Documentation
Keyring provides a common interface to a range of secure credential storage services. It was originally developed as part of [AWS Vault](https://github.com/99designs/aws-vault), a command line tool for securely managing AWS access from developer workstations.
## Supported Backends
* [macOS Keychain](https://support.apple.com/en-au/guide/keychain-access/welcome/mac)
* [Windows Credential Manager](https://support.microsoft.com/en-au/help/4026814/windows-accessing-credential-manager)
* Secret Service ([Gnome Keyring](https://wiki.gnome.org/Projects/GnomeKeyring), [KWallet](https://kde.org/applications/system/org.kde.kwalletmanager5))
* [KWallet](https://kde.org/applications/system/org.kde.kwalletmanager5)
* [Pass](https://www.passwordstore.org/)
* [Encrypted file (JWT)](https://datatracker.ietf.org/doc/html/rfc7519)
* [KeyCtl](https://linux.die.net/man/1/keyctl)
## Usage
The short version of how to use keyring is shown below.
```go
ring, _ := keyring.Open(keyring.Config{
ServiceName: "example",
})
_ = ring.Set(keyring.Item{
Key: "foo",
Data: []byte("secret-bar"),
})
i, _ := ring.Get("foo")
fmt.Printf("%s", i.Data)
```
Typical flow:
1. Open a keyring with a `keyring.Config` (at minimum a `ServiceName`).
2. Store a secret with `ring.Set(keyring.Item{Key: ..., Data: ...})` where `Data` is a `[]byte`.
3. Retrieve it with `ring.Get("key")`; the returned item's `Data` field holds the secret bytes.
For full API details, see [the keyring godocs](https://godoc.org/github.com/99designs/keyring).
## Module Import
The package is imported as:
```
github.com/99designs/keyring
```
## Notes
* The backend selected depends on the host operating system and available credential services; the library provides a common `Open`/`Get`/`Set` interface across all of them.
* Secrets are stored and returned as raw byte slices (`[]byte`), so any serializable value can be stored.
|