crypt

package module
v0.0.0-...-601d287 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: MIT Imports: 14 Imported by: 6

README

crypt library used by ECM toolkit

Documentation

Index

Constants

View Source
const (
	// KeySize is the size of a NaCl secret key
	KeySize = 32
	// NonceSize is the size of a NaCl nonce
	NonceSize = 24
)

Variables

View Source
var (
	// ErrEncrypt is returned when encryption fails.
	ErrEncrypt = errors.New("secret: encryption failed")

	// ErrDecrypt is returned when decryption fails.
	ErrDecrypt = errors.New("secret: decryption failed")
)
View Source
var SupportedCiphers = []string{"aes", "nacl"}

SupportedCiphers provides list of supported ciphers

Functions

func CreateHash

func CreateHash(key string) string

CreateHash creates a hash for given key

func CreatePassword

func CreatePassword(length int, hasNumbers bool, hasSymbols bool) string

CreatePassword creates password of certain length

func Decrypt

func Decrypt(data []byte, passphrase, cipher string) ([]byte, error)

Decrypt wrapper function to decrypt given binary data blob using given passphrase and cipher

func Encrypt

func Encrypt(data []byte, passphrase, cipher string) ([]byte, error)

Encrypt wrapper function to encrypt given binary data blob using given passphrase and cipher

func GenerateKey

func GenerateKey(passphrase string) (*[KeySize]byte, error)

GenerateKey creates a new secret key either randomly if input key is not provided or via key hash

func GenerateNonce

func GenerateNonce() (*[NonceSize]byte, error)

GenerateNonce creates a new random nonce.

func GetCipher

func GetCipher(cipher string) string

GetCipher returns either default or given cipher

Types

type Cipher

type Cipher interface {
	Encript(data []byte, key string) ([]byte, error)
	Decript(data []byte, key string) ([]byte, error)
}

Cipher defines cipher interface

type CipherAES

type CipherAES struct {
}

CipherAES represents AES Cipher

func (*CipherAES) Decrypt

func (c *CipherAES) Decrypt(data []byte, passphrase string) ([]byte, error)

Decrypt implementation for AES Cipher

func (*CipherAES) Encrypt

func (c *CipherAES) Encrypt(data []byte, passphrase string) ([]byte, error)

Encrypt implementation for AES cipher

type CipherNaCl

type CipherNaCl struct {
}

CipherNaCl represents NaCl Cipher

func (*CipherNaCl) Decrypt

func (c *CipherNaCl) Decrypt(data []byte, passphrase string) ([]byte, error)

Decrypt implementation of NaCl cipher

func (*CipherNaCl) Encrypt

func (c *CipherNaCl) Encrypt(data []byte, passphrase string) ([]byte, error)

Encrypt implementation of NaCl cipher

Jump to

Keyboard shortcuts

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