crypt

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package crypt streamlines the process of encrypting and decrypting data. It leverages the AES encryption algorithm with PBKDF2 password-based key derivation to provide a user friendly yet secure means of data protection.

Basic Usage:

c, salt := crypt.NewFromPassword("Pass123!")

ciphertext := c.Encrypt([]byte("lorem ipsum"))
fmt.Println(ciphertext)

plaintext, err := c.Decrypt(ciphertext)
fmt.Println(string(plaintext))

Index

Constants

View Source
const (
	PASSWORD_KEY_SIZE = 32 // AES-256
	PBKDF2_ITERATIONS = 100_000
	SALT_SIZE         = 16
)
View Source
const NONCE_SIZE = 12 // AES-GCM

Variables

This section is empty.

Functions

This section is empty.

Types

type Ciphertext

type Ciphertext []byte

Ciphertext is a raw byte slice containing both the nonce and the encrypted text.

func (Ciphertext) Nonce

func (ct Ciphertext) Nonce() []byte

Return the nonce portion of the ciphertext.

func (Ciphertext) Text

func (ct Ciphertext) Text() []byte

Return the text portion of the ciphertext.

type Crypt

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

func LoadFromPassword

func LoadFromPassword(password string, salt []byte) Crypt

Load a Crypt object from a password and an existing salt. Returns the object.

func New

func New(key []byte) (Crypt, error)

Create a new AES-Crypt object from a key. Key must be 16, 24, or 32 bytes.

func NewFromPassword

func NewFromPassword(password string) (Crypt, []byte)

Create a new Crypt object from a password and a random salt. Returns the object and the salt.

func (Crypt) Decrypt

func (c Crypt) Decrypt(ct Ciphertext) ([]byte, error)

Decrypt the ciphertext and return the resulting plaintext. Also returns any decryption errors.

func (Crypt) Encrypt

func (c Crypt) Encrypt(plaintext []byte) Ciphertext

Encrypt the plaintext and return the resulting ciphertext.

Jump to

Keyboard shortcuts

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