aesf

package module
v0.0.0-...-705e97d Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: MIT Imports: 11 Imported by: 0

README

AESf

Build Status

AESf package combines AES encryption, sha1HMAC verification and RFC2898 key derivation, which provide a very security way to encryp/decrypt data in golang.

Key features

  • Support AES-128, AES-192, or AES-256.
  • Use CTR mode for encrytion.
  • Sha1HMAC for signature authentication.
  • Password verify before decryption.
  • RFC2898 as salt generater.

The whole idea is coming from @BrianGladman 's blog http://www.gladman.me.uk/cryptography_technology/fileencrypt.

Installation

This package can be installed with the go get command:

go get github.com/xeodou/aesf

Documentation

API documentation can be found here: http://godoc.org/github.com/xeodou/aesf

Examples can be found under the ./example_test.go directory

License

MIT

Author

xeodou

Documentation

Overview

AESf package combines AES encryption, sha1HMAC verification and RFC2898 key derivation, which provide a very security way to encryp/decrypt data in golang.

Installation

go get github.com/xeodou/aesf

Currently aesf support AES-128, AES-192, or AES-256 three types of AES encryption.

If you want know why AES CTR is a security way to encrypt data, please see the wikipedia page here,

https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation

How do use it

```

aesf, err := New(your_password_here)

var cipher bytes.Buffer
// Encrypt a Writer
pw, err := aesf.Encrypt(&cipher)

// Create simple Reader here
r := strings.NewReader("some io.Reader stream to be read")

// Write data to encrypt
io.Copy(pw, r)

// Close the WriteCloser
pw.Close()
// You will able access the cipher data from here
// The cipher text size equal:
// salt size + 2 bytes verifier + data size + 10 sha1HMAC size
//

var plain bytes.Buffer
// Decrypt a Reader
dr, err := aesf.Decrypt(&cipher)
// ReadCloser try to read data
io.Copy(&plain, dr)
// Will do a sha1HMAC during close
dr.Close()
// You will be able access the plain text from here.
// The plain text size equal:
// data size - salt size - 2 bytes verifier - 10 sha1HMAC size

```

Index

Constants

View Source
const (
	// Default iterations of derivation key producing
	DefaultIterations = 4096
	// Authentication field size
	SignatureKeySize = 10
	// Password verifier size
	PwdVerifierSize = 2
)

Variables

View Source
var (
	// Invalid decrypt key
	ErrBadPassword = errors.New("asef: invalid password")
	// Envalid data signature
	ErrSignatureFail = errors.New("asef: invalid signature key")
)

Functions

This section is empty.

Types

type AESf

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

func New

func New(password string) (*AESf, error)

func (*AESf) Decrypt

func (aesf *AESf) Decrypt(ciphertext io.Reader) (plaintext io.ReadCloser, err error)

func (*AESf) Encrypt

func (aesf *AESf) Encrypt(ciphertext io.Writer) (plaintext io.WriteCloser, err error)

type PasswordSizeError

type PasswordSizeError int

Encrypt key size should be between 8 bytes to 64 bytes.

func (PasswordSizeError) Error

func (p PasswordSizeError) Error() string

type ReaderSizeError

type ReaderSizeError int

func (ReaderSizeError) Error

func (r ReaderSizeError) Error() string

Jump to

Keyboard shortcuts

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