Documentation
¶
Index ¶
Constants ¶
const DefaultMasterKey = "hermod-default-master-key-32byte"
DefaultMasterKey is the key used when an operator has not configured one. It is a constant in published source, so anything encrypted under it is protected from nobody; IsDefaultMasterKey exists so start-up can say so.
Variables ¶
This section is empty.
Functions ¶
func ComputeHMAC ¶
ComputeHMAC computes a SHA256 HMAC of the data using the given secret.
func Decrypt ¶
Decrypt reverses Encrypt. It tries the current derivation first and the historical one second, so data written by an older build still opens.
An error here means the ciphertext was written under a different master key. Callers must treat that as a failure and never fall back to the raw input: handing ciphertext to a database driver as if it were a password turns a key-rotation mistake into a stream of confusing authentication errors.
func EncryptWith ¶
EncryptWith encrypts using an explicitly supplied key, leaving the process key untouched.
Rotation needs this. Re-encrypting by installing the new key first and then rewriting rows would leave the process mid-rotation for as long as the rewrite takes — every concurrent read would fail — and a failure halfway through would strand some rows under each key with no way to tell which. Producing the new ciphertext up front means the switch happens once, after the data is safely written.
func GenerateToken ¶
func GenerateToken() string
func IsDefaultMasterKey ¶
func IsDefaultMasterKey() bool
IsDefaultMasterKey reports whether encryption is running on the built-in key, which means stored credentials are readable by anyone with the source.
func SetMasterKey ¶
func SetMasterKey(key string)
SetMasterKey installs key as the master key. An empty key is ignored, so a missing configuration leaves the previous key in place rather than silently falling back to a weaker one.
Note that rotating the key does not re-encrypt anything: ciphertext written under the old key stops being readable the moment this returns. Callers that rotate must re-encrypt what they own; see storage's ReEncryptSecrets.
Types ¶
This section is empty.