Documentation
¶
Overview ¶
Package secrets encrypts provider credentials, OIDC client secrets, TOTP seeds and other write-only values at rest with AES-256-GCM.
Ciphertext layout: version (1 byte) | key id (4 bytes) | nonce (12) | sealed. The key id is the first 4 bytes of SHA-256(key), so data sealed with a previous key still opens after rotation. Callers pass associated data that names the row and field ("provider:<id>:credentials"), which stops a ciphertext from being copied onto another row.
Index ¶
- Variables
- func GenerateKey() string
- func LoadOrCreateKeyFile(path string) (string, bool, error)
- type Box
- func (b *Box) CurrentKeyID() [4]byte
- func (b *Box) NeedsRotation(ciphertext []byte) bool
- func (b *Box) Open(ciphertext []byte, ad string) ([]byte, error)
- func (b *Box) OpenString(ciphertext []byte, ad string) (string, error)
- func (b *Box) Seal(plaintext []byte, ad string) ([]byte, error)
- func (b *Box) SealString(s, ad string) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
var ErrDecrypt = errors.New("secrets: cannot decrypt value")
ErrDecrypt is returned when a value can't be opened with any known key.
Functions ¶
func GenerateKey ¶
func GenerateKey() string
GenerateKey returns a new random 32-byte key, base64-encoded.
Types ¶
type Box ¶
type Box struct {
// contains filtered or unexported fields
}
Box seals and opens values. The zero value is not usable; use New.
func (*Box) CurrentKeyID ¶
CurrentKeyID is the id new values carry at bytes 1–4: the first 4 bytes of SHA-256 of the current key.
func (*Box) NeedsRotation ¶
NeedsRotation reports whether ciphertext was sealed with a previous key.
func (*Box) OpenString ¶
OpenString is Open for strings.