encrypt

package
v0.0.0-...-5728737 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSecret is an error when the secret hash is incorrect.
	ErrSecret = errors.New("failed secret")

	// ErrHash is an error when the hash is incorrect.
	ErrHash = errors.New("failed singer hash")
)

Functions

func DecryptFile

func DecryptFile(secret string, m *Msg, dst io.Writer) error

DecryptFile writes decrypted content of file with path from Msg.Value, checking Msg.KeyHash to dst using the secret and Msg.Salt.

func DecryptText

func DecryptText(secret string, m *Msg) (string, error)

DecryptText returns decrypted value from Msg.Value using the secret. Salt in m.Salt is expected

func Hash

func Hash(data []byte) []byte

Hash returns SHA3 ShakeSum256 check sum with length 32 bit.

func Key

func Key(secret string, salt []byte) ([]byte, []byte)

Key calculates and returns secret key and its SHA512 hash.

func Random

func Random(n int) ([]byte, error)

Random returns n-Random bytes.

func Salt

func Salt() ([]byte, error)

Salt returns Random bytes.

Types

type Msg

type Msg struct {
	Salt     string
	Value    string
	KeyHash  string
	DataHash string
	// contains filtered or unexported fields
}

Msg is struct with base parameter/results of encryption/decryption.

func File

func File(secret string, src io.Reader, base, name string) (*Msg, error)

File encrypts content from src to a new file using the secret. Salt and key hash are returned as Msg.Salt and Msg.KeyHash. The name if new file will be stored in m.Value.

func Text

func Text(secret, plainText string) (*Msg, error)

Text encrypts plaintText using the secret. Cipher message will be returned as Msg.Value.

type StreamSigner

type StreamSigner struct {
	R io.Reader
	W io.Writer
	// contains filtered or unexported fields
}

StreamSigner is a wrapper for stream Read/Write and hash sum calculations together.

func NewStreamSigner

func NewStreamSigner(src io.Reader, dst io.Writer) *StreamSigner

NewStreamSigner returns new StreamSigner.

func (*StreamSigner) Read

func (s *StreamSigner) Read(p []byte) (n int, err error)

Read reads data from s.R. It's used for stream encryption.

func (*StreamSigner) ReaderHashSum

func (s *StreamSigner) ReaderHashSum() ([]byte, error)

ReaderHashSum calculates and returns s.R hash.

func (*StreamSigner) Write

func (s *StreamSigner) Write(p []byte) (n int, err error)

Write writes data to s.W. It's used for stream decryption.

func (*StreamSigner) WriterHashSum

func (s *StreamSigner) WriterHashSum() ([]byte, error)

WriterHashSum calculates and returns s.W hash.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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