crypto

package
v0.0.0-...-63c5a8c Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigTypeOpenPGP    = "openpgp"
	ConfigTypeAESGCM     = "aes_gcm"
	ConfigTypeChaChaPoly = "chachapoly"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AESGCMClient

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

func NewAESGCMClient

func NewAESGCMClient(settings *AESGCMSettings) (*AESGCMClient, error)

func (*AESGCMClient) Decrypt

func (c *AESGCMClient) Decrypt(data []byte, password []byte) ([]byte, error)

func (*AESGCMClient) Encrypt

func (c *AESGCMClient) Encrypt(plaintext []byte, password []byte) (data []byte, err error)

type AESGCMSettings

type AESGCMSettings struct {
	KeyLen        int            `json:"keylen,omitempty" toml:"keylen"`
	KeyDerivation string         `json:"keyderivation,omitempty" toml:"keyderivation"`
	PBKDF2        *pbkdf2.PBKDF2 `json:"pbkdf2,omitempty" toml:"pbkdf2"`
	Scrypt        *scrypt.Scrypt `json:"scrypt,omitempty" toml:"scrypt"`
	// Warning: Deprecated. These three Pbkdf2 configs are required for backwards-compatibility :(
	Pbkdf2Hash       string `json:"pbkdf2hash,omitempty" toml:"pbkdf2hash"`
	Pbkdf2Iterations int    `json:"pbkdf2iterations,omitempty" toml:"pbkdf2iterations"`
	Pbkdf2SaltLen    int    `json:"pbkdf2saltlen,omitempty" toml:"pbkdf2saltlen"`
}

func DefaultAESGCMSettings

func DefaultAESGCMSettings() *AESGCMSettings

type AESGCMStore

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

type ChaCha20Poly1305Client

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

func NewChaCha20Poly1305Client

func NewChaCha20Poly1305Client(settings *ChaCha20Poly1305Settings) (*ChaCha20Poly1305Client, error)

func (*ChaCha20Poly1305Client) Decrypt

func (c *ChaCha20Poly1305Client) Decrypt(data []byte, password []byte) ([]byte, error)

func (*ChaCha20Poly1305Client) Encrypt

func (c *ChaCha20Poly1305Client) Encrypt(plaintext []byte, password []byte) (data []byte, err error)

type ChaCha20Poly1305Settings

type ChaCha20Poly1305Settings struct {
	KeyDerivation string         `json:"keyderivation,omitempty" toml:"keyderivation"`
	PBKDF2        *pbkdf2.PBKDF2 `json:"pbkdf2,omitempty" toml:"pbkdf2"`
	Scrypt        *scrypt.Scrypt `json:"scrypt,omitempty" toml:"scrypt"`
}

func DefaultChaCha20Poly1305Settings

func DefaultChaCha20Poly1305Settings() *ChaCha20Poly1305Settings

type ChaCha20Poly1305Store

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

type Client

type Client interface {
	Decrypt(data, password []byte) (plaintext []byte, err error)
	Encrypt(plaintext, password []byte) (data []byte, err error)
}

func New

func New(config *Config) (Client, error)

type Config

type Config struct {
	Type                      string `json:"type" toml:"type"`
	*OpenPGPSettings          `json:"openpgp,omitempty" toml:"openpgp"`
	*AESGCMSettings           `json:"aes_gcm,omitempty" toml:"aes_gcm"`
	*ChaCha20Poly1305Settings `json:"chachapoly,omitempty" toml:"chachapoly"`
}

func NewDefaultConfig

func NewDefaultConfig() Config

func NewDefaultConfigWithType

func NewDefaultConfigWithType(t string) Config

type KeyDerivation

type KeyDerivation interface {
	DeriveKey(password []byte, keyLen int) (key []byte, salt []byte, err error)
	DeriveKeyWithSalt(password, salt []byte, keyLen int) (key []byte, err error)
}

type OpenPGPClient

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

func NewOpenPGPClient

func NewOpenPGPClient(settings *OpenPGPSettings) (*OpenPGPClient, error)

func (*OpenPGPClient) Decrypt

func (c *OpenPGPClient) Decrypt(ciphertext []byte, password []byte) ([]byte, error)

decrypt uses PGP to decrypt symmetrically encrypted and armored text with the provided password.

func (*OpenPGPClient) Encrypt

func (c *OpenPGPClient) Encrypt(plaintext []byte, password []byte) ([]byte, error)

encrypt uses PGP to symmetrically encrypt and armor text with the provided password.

type OpenPGPSettings

type OpenPGPSettings struct {
	Cipher   string `json:"cipher,omitempty" toml:"cipher"`
	S2KCount int    `json:"s2kcount,omitempty" toml:"s2kcount"`
}

func DefaultOpenPGPSettings

func DefaultOpenPGPSettings() *OpenPGPSettings

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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