Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeKey(encodedKey string) ([]byte, error)
- func EncodeKey(key []byte) string
- func GenerateKey() ([]byte, error)
- func RandomKey32() []byte
- type AES256GCM
- type Credential
- func CredentialFromConfig(cfg CredentialConfig, encryptionKey []byte, allowEmpty bool) (*Credential, error)
- func CredentialFromEnv(envName string, encryptionKey []byte, allowEmpty bool) (*Credential, error)
- func CredentialFromFile(filename string, encryptionKey []byte, allowEmpty bool) (*Credential, error)
- func NewCredential(data []byte, encryptionKey []byte, allowEmpty bool) (*Credential, error)
- func RandomCredential(l int) (*Credential, error)
- type CredentialConfig
- type DefaultCredentialConfig
- type EncryptionProvider
- type KeyConfig
- type Secret
Constants ¶
Variables ¶
Functions ¶
func GenerateKey ¶
GenerateKey generates a random 32-byte key for AES-256
Types ¶
type AES256GCM ¶ added in v0.6.0
type AES256GCM interface { Encrypt(data []byte) ([]byte, error) Decrypt(data []byte) ([]byte, error) Clear() }
func NewAES256GCM ¶ added in v0.6.0
NewAES256GCM creates a AES256GCM object
type Credential ¶
type Credential struct {
// contains filtered or unexported fields
}
Credential stores sensitive information (like passwords) in encrypted form in memory
func CredentialFromConfig ¶
func CredentialFromConfig(cfg CredentialConfig, encryptionKey []byte, allowEmpty bool) (*Credential, error)
CredentialFromConfig attempts to parse credentials from a CredentialConfig struct if no valid credentials found, returns error; if environment var is used, it is read only once and then overwritten with an empty value
func CredentialFromEnv ¶
func CredentialFromEnv(envName string, encryptionKey []byte, allowEmpty bool) (*Credential, error)
CredentialFromEnv creates a Credential from an environment variable
func CredentialFromFile ¶
func CredentialFromFile(filename string, encryptionKey []byte, allowEmpty bool) (*Credential, error)
CredentialFromFile creates a Credential from a secrets file
func NewCredential ¶
func NewCredential(data []byte, encryptionKey []byte, allowEmpty bool) (*Credential, error)
NewCredential creates a new secure credential container The encryption key should be unique per application instance You can use env variables, hardware tokens, etc. as the source of the encryption key
func RandomCredential ¶ added in v0.5.0
func RandomCredential(l int) (*Credential, error)
RandomCredential create a secure credential using random bytes
func (*Credential) Get ¶
func (sc *Credential) Get() (string, error)
Get decrypts and returns the plaintext credential
func (*Credential) GetBytes ¶ added in v0.5.0
func (sc *Credential) GetBytes() ([]byte, error)
GetBytes decrypts and returns the raw credential This should be called only when needed to minimize exposure of the sensitive data in memory
func (*Credential) IsEmpty ¶
func (sc *Credential) IsEmpty() bool
IsEmpty returns true if credentials is empty
func (*Credential) Update ¶
func (sc *Credential) Update(plaintext string) error
Update updates the credential with a new plaintext value
func (*Credential) UpdateBytes ¶ added in v0.5.0
func (sc *Credential) UpdateBytes(data []byte) error
UpdateBytes updates the credential with a new value
type CredentialConfig ¶
type DefaultCredentialConfig ¶
type DefaultCredentialConfig struct { Password string `json:"password"` // Password plaintext password; if set, is used instead of the rest PasswordEnvVar string `json:"passwordEnvVar"` // PasswordEnvVar name of env var with secret PasswordFile string `json:"passwordFile"` // PasswordFile name of secrets file, to be read; if none of the above set, this one is used }
DefaultCredentialConfig misc options for credentials if different field names are required, just implement CredentialConfig interface
func (DefaultCredentialConfig) Fetch ¶ added in v0.5.0
func (c DefaultCredentialConfig) Fetch() (string, error)
Fetch retrieve the contents of the credential
func (DefaultCredentialConfig) IsEmpty ¶ added in v0.5.0
func (c DefaultCredentialConfig) IsEmpty() bool
IsEmpty returns true if credential source is empty