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 ¶
const ( PASSWORD_KEY_SIZE = 32 // AES-256 PBKDF2_ITERATIONS = 100_000 SALT_SIZE = 16 )
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 ¶
Load a Crypt object from a password and an existing salt. Returns the object.
func NewFromPassword ¶
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.