crypt

package
v0.83.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: BSD-3-Clause Imports: 7 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey() (string, error)

GenerateKey generates a new random 32-byte encryption key and returns it as base64.

Types

type FieldEncrypt

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

FieldEncrypt provides AES-GCM encryption for sensitive fields.

func NewFieldEncrypt

func NewFieldEncrypt(base64Key string) (*FieldEncrypt, error)

NewFieldEncrypt creates a new FieldEncrypt with the given base64-encoded key. The key must be 32 bytes when decoded (for AES-256).

func (*FieldEncrypt) Decrypt

func (f *FieldEncrypt) Decrypt(ciphertext string) (string, error)

Decrypt decrypts the given base64-encoded ciphertext and returns the plaintext. Returns empty string for empty input.

func (*FieldEncrypt) Encrypt

func (f *FieldEncrypt) Encrypt(plaintext string) (string, error)

Encrypt encrypts the given plaintext and returns base64-encoded ciphertext. Returns empty string for empty input.

func (*FieldEncrypt) LegacyDecrypt added in v0.64.1

func (f *FieldEncrypt) LegacyDecrypt(ciphertext string) (string, error)

LegacyDecrypt decrypts ciphertext that was encrypted using AES-CBC with a static IV. Deprecated: This method is kept only for backward compatibility with existing encrypted data.

func (*FieldEncrypt) LegacyEncrypt added in v0.64.1

func (f *FieldEncrypt) LegacyEncrypt(plaintext string) string

LegacyEncrypt encrypts plaintext using AES-CBC with a static IV. Deprecated: Use Encrypt instead. This method is kept only for backward compatibility.

Jump to

Keyboard shortcuts

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