crypto

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptWith

func DecryptWith(s EncString, key SymmetricEncryptionKey) ([]byte, error)

func DecryptWithAsymmetric

func DecryptWithAsymmetric(s []byte, asymmetrickey AsymmetricEncryptionKey) ([]byte, error)

func EncryptWithAsymmetric

func EncryptWithAsymmetric(s []byte, asymmbetrickey AsymmetricEncryptionKey) ([]byte, error)

func EncryptWithToString

func EncryptWithToString(data []byte, encType EncStringType, key SymmetricEncryptionKey) (string, error)

func InitKeyringFromMasterKey

func InitKeyringFromMasterKey(keyring *Keyring, accountKey EncString, accountPrivateKey EncString, orgKeys map[string]string, masterKey MasterKey) error

func InitKeyringFromMasterPassword

func InitKeyringFromMasterPassword(keyring *Keyring, accountKey EncString, accountPrivateKey EncString, orgKeys map[string]string, password []byte, email string, kdfConfig KDFConfig) error

func InitKeyringFromUserSymmetricKey

func InitKeyringFromUserSymmetricKey(keyring *Keyring, accountSymmetricKey SymmetricEncryptionKey, accountPrivateKey EncString, orgKeys map[string]string) error

Types

type AsymmetricEncryptionKey

type AsymmetricEncryptionKey interface {
	PublicBytes() []byte
	PrivateBytes() ([]byte, error)
}

func GenerateAsymmetric

func GenerateAsymmetric(useMemguard bool) (AsymmetricEncryptionKey, error)

type EncString

type EncString struct {
	Type        EncStringType
	IV, CT, MAC []byte
}

func EncryptWith

func EncryptWith(data []byte, encType EncStringType, key SymmetricEncryptionKey) (EncString, error)

func (EncString) IsNull

func (s EncString) IsNull() bool

func (EncString) MarshalText

func (s EncString) MarshalText() ([]byte, error)

func (*EncString) UnmarshalText

func (s *EncString) UnmarshalText(data []byte) error

type EncStringType

type EncStringType int
const (
	AesCbc256_B64                     EncStringType = 0
	AesCbc128_HmacSha256_B64          EncStringType = 1
	AesCbc256_HmacSha256_B64          EncStringType = 2
	Rsa2048_OaepSha256_B64            EncStringType = 3
	Rsa2048_OaepSha1_B64              EncStringType = 4
	Rsa2048_OaepSha256_HmacSha256_B64 EncStringType = 5
	Rsa2048_OaepSha1_HmacSha256_B64   EncStringType = 6
)

func (EncStringType) HasMAC

func (t EncStringType) HasMAC() bool

type KDFConfig

type KDFConfig struct {
	Type        KDFType
	Iterations  uint32
	Memory      uint32
	Parallelism uint32
}

type KDFType

type KDFType int
const (
	PBKDF2   KDFType = 0
	Argon2ID KDFType = 1
)

type Keyring

type Keyring struct {
	AsymmetricEncyryptionKey AsymmetricEncryptionKey
	IsMemguard               bool
	OrganizationKeys         map[string]string
	// contains filtered or unexported fields
}

func NewMemguardKeyring

func NewMemguardKeyring(accountKey *MemguardSymmetricEncryptionKey) Keyring

func NewMemoryKeyring

func NewMemoryKeyring(accountKey *MemorySymmetricEncryptionKey) Keyring

func (*Keyring) GetAccountKey

func (keyring *Keyring) GetAccountKey() SymmetricEncryptionKey

func (*Keyring) GetSymmetricKeyForOrganization

func (keyring *Keyring) GetSymmetricKeyForOrganization(uuid string) (SymmetricEncryptionKey, error)

func (Keyring) IsLocked

func (keyring Keyring) IsLocked() bool

func (*Keyring) Lock

func (keyring *Keyring) Lock()

func (*Keyring) UnlockWithAccountKey

func (keyring *Keyring) UnlockWithAccountKey(accountKey SymmetricEncryptionKey)

type MasterKey

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

func DeriveMasterKey

func DeriveMasterKey(password []byte, email string, kdfConfig KDFConfig) (MasterKey, error)

func MasterKeyFromBytes

func MasterKeyFromBytes(key []byte) MasterKey

func (MasterKey) GetBytes

func (masterKey MasterKey) GetBytes() []byte

type MemguardAsymmetricEncryptionKey

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

func MemguardAsymmetricEncryptionKeyFromBytes

func MemguardAsymmetricEncryptionKeyFromBytes(key []byte) (MemguardAsymmetricEncryptionKey, error)

func (MemguardAsymmetricEncryptionKey) PrivateBytes

func (key MemguardAsymmetricEncryptionKey) PrivateBytes() ([]byte, error)

func (MemguardAsymmetricEncryptionKey) PublicBytes

func (key MemguardAsymmetricEncryptionKey) PublicBytes() []byte

type MemguardSymmetricEncryptionKey

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

func MemguardSymmetricEncryptionKeyFromBytes

func MemguardSymmetricEncryptionKeyFromBytes(key []byte) (MemguardSymmetricEncryptionKey, error)

func (MemguardSymmetricEncryptionKey) Bytes

func (key MemguardSymmetricEncryptionKey) Bytes() []byte

func (MemguardSymmetricEncryptionKey) EncryptionKeyBytes

func (key MemguardSymmetricEncryptionKey) EncryptionKeyBytes() ([]byte, error)

func (MemguardSymmetricEncryptionKey) MacKeyBytes

func (key MemguardSymmetricEncryptionKey) MacKeyBytes() ([]byte, error)

type MemoryAsymmetricEncryptionKey

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

func MemoryAsymmetricEncryptionKeyFromBytes

func MemoryAsymmetricEncryptionKeyFromBytes(key []byte) (MemoryAsymmetricEncryptionKey, error)

func (MemoryAsymmetricEncryptionKey) PrivateBytes

func (key MemoryAsymmetricEncryptionKey) PrivateBytes() ([]byte, error)

func (MemoryAsymmetricEncryptionKey) PublicBytes

func (key MemoryAsymmetricEncryptionKey) PublicBytes() []byte

type MemorySymmetricEncryptionKey

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

func MemorySymmetricEncryptionKeyFromBytes

func MemorySymmetricEncryptionKeyFromBytes(key []byte) (MemorySymmetricEncryptionKey, error)

func (MemorySymmetricEncryptionKey) Bytes

func (key MemorySymmetricEncryptionKey) Bytes() []byte

func (MemorySymmetricEncryptionKey) EncryptionKeyBytes

func (key MemorySymmetricEncryptionKey) EncryptionKeyBytes() ([]byte, error)

func (MemorySymmetricEncryptionKey) MacKeyBytes

func (key MemorySymmetricEncryptionKey) MacKeyBytes() ([]byte, error)

type SymmetricEncryptionKey

type SymmetricEncryptionKey interface {
	Bytes() []byte
	EncryptionKeyBytes() ([]byte, error)
	MacKeyBytes() ([]byte, error)
}

Jump to

Keyboard shortcuts

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