key

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default options to use when generating a key.
	DefaultEncryption = OptionsConfig{
		Algorithm:         AES256CBC,
		Iterations:        1,
		MinPasswordLength: 32,
		SaltBits:          256,
	}
	// Default options to use when generating a key for integrity.
	DefaultIntegrity = OptionsConfig{
		Algorithm:         SHA256,
		Iterations:        1,
		MinPasswordLength: 32,
		SaltBits:          256,
	}
)

Functions

This section is empty.

Types

type Algorithm

type Algorithm int64

The type of encryption algorithm to use.

const (
	// AES-256-CBC.
	AES256CBC Algorithm = iota
	// AES-128-CTR.
	AES128CTR
	// SHA-256.
	SHA256
)

type Config

type Config struct {
	// Password to use. If not specified, the password buffer will be used.
	Password string
	// Password buffer to use. If not specified, the password will be used.
	PasswordBuffer []byte
	// Encryption options.
	Options OptionsConfig
}

Key generation options.

type GeneratedKey

type GeneratedKey struct {
	// AES128CTR | AES256CBC | SHA256
	Algorithm Algorithm
	// Encryption key.
	Key []byte
	// Salt used.
	Salt string
	// IV used.
	IV []byte
}

Key generation result.

func Generate

func Generate(cfg Config) (GeneratedKey, error)

Generate a key to use for encryption.

type OptionsConfig

type OptionsConfig struct {
	// AES128CTR | AES256CBC | SHA256
	Algorithm Algorithm
	// Total number of iterations to use. More iterations are more secure but slower.
	Iterations int
	// Minimum password length. Shorter passwords are less secure.
	MinPasswordLength int
	// Number of bits to use in the salt. More bits are more secure but slower.
	SaltBits int
	// Salt to use. If not specified, a random salt will be generated.
	Salt string
	// IV to use. If not specified, a random IV will be generated.
	IV []byte
}

Encryption options.

Jump to

Keyboard shortcuts

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