crypto

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMacError = fmt.Errorf("MAC error")
)

Functions

func HashedPassword

func HashedPassword(salt, password string, kdf int, iterations int) string

func MakeInternalKey

func MakeInternalKey(salt, password string, kdf, iterations int) []byte

Types

type CryptoKey

type CryptoKey struct {
	Key []byte
	Mac []byte
}

func NewKey

func NewKey(key, mac []byte) *CryptoKey

NewKey returns a new CryptoKey for AES-256-CBC

func (*CryptoKey) Check

func (k *CryptoKey) Check(data *Encrypted) bool

Check the integrity of the data using HMAC, if the key has a MAC

func (*CryptoKey) Decrypt

func (k *CryptoKey) Decrypt(data *Encrypted) ([]byte, error)

Decrypt data using AES-256-CBC

func (*CryptoKey) DecryptStr

func (k *CryptoKey) DecryptStr(data string) (string, error)

func (*CryptoKey) Encrypt

func (k *CryptoKey) Encrypt(data []byte) (*Encrypted, error)

Encrypt data using AES-256-CBC

func (*CryptoKey) String

func (k *CryptoKey) String() string

Return the CryptoKey as a string

type Encrypted

type Encrypted struct {
	Type  uint   `json:"type"`          // Cypher type
	Iv    string `json:"iv,omitempty"`  // Initialization Vector in base64 (for decryption)
	Value string `json:"value"`         // Encrypted value in base64
	Mac   string `json:"mac,omitempty"` // Message Authentication Hash (HMAC) in base64
}

func MakeEncKey

func MakeEncKey(key []byte) (*Encrypted, error)

func NewEncrypted

func NewEncrypted(s string) (*Encrypted, error)

NewEncrypted returns a new Encrypted object from a string

func (*Encrypted) String

func (k *Encrypted) String() string

Return the encrypted value as a string

Jump to

Keyboard shortcuts

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