iocrypt

package module
v0.0.0-...-6804bed Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

iocrypt

Build Status Go Report Card GoDoc

I/O encryption/decryption library in Go.

This is a simple library that allows I/O streams to be easily encrypted and decrypted using Go's standard AES/GCM implementation. Unlike the original libraries, which operate on slices of bytes, iocrypt reads, encrypts, and saves data in chunks, allowing the use of large data sets.

SUPER IMPORTANT DISCLAIMER

I am NOT a cryptographer and I wrote this code in one afternoon. This library makes use of the the standard libraries to encrypt/decrypt a file in "chunks", so it should be safe. Use at your own risk. Feel free to review the code and report any problems.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(r io.Reader, w io.Writer, key []byte) (int, error)

Decrypt decrypts an encrypted data stream from an io.Reader into an io.Writer using the specified key, and returns the number of bytes written to the io.Writer.

func DecryptN

func DecryptN(r io.Reader, w io.Writer, key []byte, maxlen int) (int, error)

DecryptN decrypts an encrypted data stream from an io.Reader into an io.Writer using the specified key, and returns the number of bytes written to the io.Writer. The maximum length limits the number of bytes to read from the input stream (including the encryption block headers.) If the maximum length is set to zero, the function consumes all bytes in the input stream. Nonces are read from the input stream.

func Encrypt

func Encrypt(r io.Reader, w io.Writer, key []byte) (int, error)

Encrypt encrypts data from an io.Reader into an io.Writer using the specified key, and returns the number of bytes written to the io.Writer.

Example
r := bytes.NewBufferString("Vanilla Plaintext")
w := &bytes.Buffer{}

key, err := RandomAES128Key()
if err != nil {
	log.Fatal(err)
}

n, err := Encrypt(r, w, key)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Wrote %d encrypted bytes\n", n)
Output:

Wrote 57 encrypted bytes

func RandomAES128Key

func RandomAES128Key() ([]byte, error)

RandomAES128Key returns a randomly generated AES128 key.

func RandomAES256Key

func RandomAES256Key() ([]byte, error)

RandomAES256Key returns a randomly generated AES256 key.

Types

This section is empty.

Jump to

Keyboard shortcuts

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