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: 5 modules, 5 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.

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