crypt

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 11 Imported by: 0

README

go-crypt

release-badge status-badge GoDoc

go-crypt provides a simple interface for AES encryption and decryption of files in Go. It uses AES-GCM for encryption and HKDF for key derivation from a passphrase and a random salt.

Features

  • Simple Load and Save methods for file-based encryption.
  • io.Reader and io.Writer interfaces for streaming data.
  • Key derivation using HKDF-SHA256 with a random salt.
  • AES-256-GCM encryption.
  • Versioned storage for forward compatibility.

Authors

  • Christophe Lambin

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Crypt

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

func New

func New(filePath string, passphrase string) Crypt

func (Crypt) Load

func (c Crypt) Load() ([]byte, error)

func (Crypt) Reader

func (c Crypt) Reader() io.Reader

func (Crypt) Save

func (c Crypt) Save(body []byte) (err error)
Example
c := New(filepath.Join(os.TempDir(), "test-crypt.json"), "my-passphrase")
_ = c.Save([]byte("hello world"))
output, _ := c.Load()
fmt.Println(string(output))
Output:
hello world

func (Crypt) Writer

func (c Crypt) Writer() io.WriteCloser
Example
type record struct {
	Name string `json:"name"`
}

c := New(filepath.Join(os.TempDir(), "test-crypt.json"), "my-passphrase")
input := record{Name: "john doe"}

w := c.Writer()
// encrypt
_ = json.NewEncoder(w).Encode(input)
// write to file
_ = w.Close()

// read using io.Reader
var output record
_ = json.NewDecoder(c.Reader()).Decode(&output)
fmt.Println(output.Name)
Output:
john doe

type ErrDecryptionFailed

type ErrDecryptionFailed struct {
	Err error
}

func (*ErrDecryptionFailed) Error

func (e *ErrDecryptionFailed) Error() string

func (*ErrDecryptionFailed) Unwrap

func (e *ErrDecryptionFailed) Unwrap() error

Jump to

Keyboard shortcuts

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