crypto

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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