crypt

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Taken and adapted from: - https://github.com/schollz/croc/blob/8dc5bd6e046194d0c5b1dc34b0fd1602f8f6c7ad/src/crypt/crypt.go#L1 - https://github.com/blend/go-sdk/blob/29e67762ae016aba504d9de96bd99cd4b23728f7/crypto/stream.go#L23

Index

Constants

View Source
const NonceLength = 12

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(key []byte, data []byte) ([]byte, error)

Decrypt uses key to decrypt the given data.

func DeriveKey added in v0.3.0

func DeriveKey(pw []byte, salt []byte) ([]byte, error)

DeriveKey uses scrypt to generated a fixed size key for further encryption/decryption steps aka. to initialise the block cipher. After minimal research I chose scrypt over pbkdf2 as apparently scrypt contains pbkdf2? Which is a good thing I guess. The parameters below are taken from example test in the scrypt package.

func Encrypt

func Encrypt(key []byte, data []byte) ([]byte, error)

Encrypt will encrypt the data with the given key.

Types

type StreamDecrypter added in v0.3.0

type StreamDecrypter struct {
	// contains filtered or unexported fields
}

StreamDecrypter is a decrypter for a stream of data with authentication

func NewStreamDecrypter added in v0.3.0

func NewStreamDecrypter(key []byte, iv []byte, src io.Reader) (*StreamDecrypter, error)

NewStreamDecrypter creates a new stream decrypter

func (*StreamDecrypter) Authenticate added in v0.3.0

func (s *StreamDecrypter) Authenticate(hash []byte) error

Authenticate verifies that the hash of the stream is correct. This should only be called after processing is finished

func (*StreamDecrypter) Read added in v0.3.0

func (s *StreamDecrypter) Read(p []byte) (int, error)

Read reads bytes from the underlying reader and then decrypts them.

type StreamEncrypter added in v0.3.0

type StreamEncrypter struct {
	// contains filtered or unexported fields
}

StreamEncrypter implements the Reader interface to be used in streaming scenarios.

func NewStreamEncrypter added in v0.3.0

func NewStreamEncrypter(key []byte, dest io.Writer) (*StreamEncrypter, error)

NewStreamEncrypter initializes a stream encrypter.

func (*StreamEncrypter) Hash added in v0.3.0

func (s *StreamEncrypter) Hash() []byte

Hash should be called after the whole payload was read. It returns the SHA-256 hash of the payload.

func (*StreamEncrypter) InitializationVector added in v0.3.0

func (s *StreamEncrypter) InitializationVector() []byte

func (*StreamEncrypter) Write added in v0.4.0

func (s *StreamEncrypter) Write(p []byte) (int, error)

Write writes bytes encrypted to the writer interface.

Jump to

Keyboard shortcuts

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