crypto

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 24, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeySize is the size of the encryption key in bytes (32 bytes = 256 bits)
	KeySize = 32
	// NonceSize is the size of the nonce for GCM mode (12 bytes is recommended)
	NonceSize = 12
	// SaltSize is the size of the salt for key derivation (32 bytes)
	SaltSize = 32
	// Iterations is the number of iterations for PBKDF2
	Iterations = 100000
)

Variables

This section is empty.

Functions

func GeneratePassword

func GeneratePassword(length int) (string, error)

GeneratePassword generates a random password for encryption

func SecureZero

func SecureZero(data []byte)

SecureZero securely zeros out sensitive byte slices

func ValidatePassword

func ValidatePassword(password string) error

ValidatePassword validates a password meets minimum requirements

Types

type EncryptedData

type EncryptedData struct {
	Salt       []byte `json:"salt"`
	Nonce      []byte `json:"nonce"`
	Ciphertext []byte `json:"ciphertext"`
}

EncryptedData represents encrypted data with metadata

type Encryptor

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

Encryptor handles encryption and decryption operations

func NewEncryptor

func NewEncryptor(password string) *Encryptor

NewEncryptor creates a new encryptor with the given password

func (*Encryptor) Decrypt

func (e *Encryptor) Decrypt(data *EncryptedData) ([]byte, error)

Decrypt decrypts encrypted data using AES-256-GCM

func (*Encryptor) DecryptString

func (e *Encryptor) DecryptString(encoded string) (string, error)

DecryptString decrypts a base64-encoded string

func (*Encryptor) Encrypt

func (e *Encryptor) Encrypt(plaintext []byte) (*EncryptedData, error)

Encrypt encrypts plaintext data using AES-256-GCM

func (*Encryptor) EncryptString

func (e *Encryptor) EncryptString(plaintext string) (string, error)

EncryptString encrypts a string and returns base64-encoded result

Jump to

Keyboard shortcuts

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