Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateKey ¶
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.