credvault

package
v0.0.0-...-36d6306 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package credvault provides encryption/decryption for credential secrets. It supports multiple algorithms via EncryptionType enum, with XChaCha20-Poly1305 as the recommended default.

Index

Constants

View Source
const (
	// KeySize is the required size for the master encryption key (256-bit).
	KeySize = 32
)

Variables

View Source
var (
	ErrInvalidKeySize     = errors.New("credvault: key must be 32 bytes")
	ErrCiphertextTooShort = errors.New("credvault: ciphertext too short")
	ErrUnsupportedType    = errors.New("credvault: unsupported encryption type")
)

Functions

This section is empty.

Types

type EncryptionType

type EncryptionType = int8

EncryptionType specifies the algorithm used to encrypt credential secrets.

const (
	EncryptionNone              EncryptionType = 0 // Plaintext (no encryption)
	EncryptionXChaCha20Poly1305 EncryptionType = 1 // XChaCha20-Poly1305 AEAD (recommended)
	EncryptionAES256GCM         EncryptionType = 2 // AES-256-GCM AEAD
)

type Vault

type Vault struct {
	// contains filtered or unexported fields
}

Vault handles encryption and decryption of credential secrets.

func New

func New(masterKey []byte) (*Vault, error)

New creates a new Vault with the given master key. The key must be exactly 32 bytes (256-bit).

func NewDefault

func NewDefault() *Vault

NewDefault creates a Vault with a static all-zeros key. Good for obfuscation (not plaintext), but not cryptographically secure.

func (*Vault) Decrypt

func (v *Vault) Decrypt(ciphertext []byte, encType EncryptionType) ([]byte, error)

Decrypt decrypts ciphertext using the specified encryption type. For EncryptionNone, returns the ciphertext unchanged.

func (*Vault) DecryptString

func (v *Vault) DecryptString(ciphertext []byte, encType EncryptionType) (string, error)

DecryptString is a convenience method for decrypting to a string.

func (*Vault) Encrypt

func (v *Vault) Encrypt(plaintext []byte, encType EncryptionType) ([]byte, error)

Encrypt encrypts plaintext using the specified encryption type. For EncryptionNone, returns the plaintext unchanged.

func (*Vault) EncryptString

func (v *Vault) EncryptString(plaintext string, encType EncryptionType) ([]byte, error)

EncryptString is a convenience method for encrypting strings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL