encrypt

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CIPHER_KEY_LEN = 32
	SALT_KEY_LEN   = 32
)

Variables

This section is empty.

Functions

func Sha256Hash

func Sha256Hash(key string) []byte

Sha256Hash utility tool

Types

type Decryptor

type Decryptor interface {
	Decrypt([]byte) ([]byte, error)
}

Decryptor decrypts encrypted data

type EncryptTool

type EncryptTool struct {
	Passphrase []byte
	Time       uint32
	Memory     uint32
	Threads    uint8
	KeyLen     uint32
}

EncryptTool implements Hasher, Encryptor and Decryptor

func New

func New(opts ...EncryptToolOption) (*EncryptTool, error)

New created a Encryptor/Decryptor/Hasher object with given options

func (*EncryptTool) Compare

func (e *EncryptTool) Compare(data, hash []byte) (bool, error)

Compare compares data which is hashed with Hash

func (*EncryptTool) Decrypt

func (e *EncryptTool) Decrypt(data []byte) ([]byte, error)

Decrypt decrypts given data

func (*EncryptTool) DeriveKey

func (e *EncryptTool) DeriveKey(salt []byte) ([]byte, []byte, error)

DeriveKey generates a key based on passphrase and salt if given

func (*EncryptTool) Encrypt

func (e *EncryptTool) Encrypt(data []byte) ([]byte, error)

Encrypt encrypts given data

func (*EncryptTool) Hash

func (e *EncryptTool) Hash(data []byte) ([]byte, error)

Hash hashes given data with argon2id

type EncryptToolOption

type EncryptToolOption func(*EncryptTool)

EncryptToolOption allows you to define options

func WithKeyLen

func WithKeyLen(keyLen uint32) EncryptToolOption

WithKeyLen option set argon2id key Length

func WithMemory

func WithMemory(memory uint32) EncryptToolOption

WithMemory option set argon2id memory

func WithPassphrase

func WithPassphrase(passphrase []byte) EncryptToolOption

WithPassphrase option sets passphrase as encryption key

func WithPassphraseText

func WithPassphraseText(passphrase string) EncryptToolOption

WithPassphraseText option sets sha256 hash of passphrase as encryption key

func WithThreads

func WithThreads(threads uint8) EncryptToolOption

WithThreads option set argon2id threads

func WithTime

func WithTime(time uint32) EncryptToolOption

WithTime option set argon2id time

type Encryptor

type Encryptor interface {
	Encrypt([]byte) ([]byte, error)
}

Encryptor encrypts data

type Hasher

type Hasher interface {
	Hash([]byte) ([]byte, error)
	Compare([]byte, []byte) (bool, error)
}

Hasher represent the interface to use one-way hash

Jump to

Keyboard shortcuts

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