cryptoutils

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 13 Imported by: 1

README

cryptoutils

Set of crypto utilities for every day use.

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

func HexDecrypt added in v0.0.2

func HexDecrypt(entry, salt, cipher string) (string, error)

HexDecript decrypts hex encoded cipher string

func HexEncrypt added in v0.0.2

func HexEncrypt(entry, salt, cipher string) (string, error)

HexEncrypt entry entry into hex encoded cipher string

func InList

func InList(a string, list []string) bool

InList checks item in a list

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