Help us shape the future of Go! Take the 2026 Go Developer Survey

dataprotection

package
v0.29.306 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package dataprotection provides authenticated encryption of small payloads behind the Provider interface, plus helpers to protect and unprotect JSON objects as base64url strings. NewSymmetric derives an AES-256-GCM key from a caller supplied high-entropy secret with HKDF-SHA256; the protected blob is nonce || ciphertext || tag with no key identifier, so key rotation must be handled by the caller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProtectObject added in v0.9.0

func ProtectObject(ctx context.Context, p Provider, v any) (string, error)

ProtectObject returns encrypted object value in base64url encoded format

func UnprotectObject added in v0.9.0

func UnprotectObject(ctx context.Context, p Provider, protected string, v any) error

UnprotectObject decrypts and unmarshals protected Base64 encoded string to a struct

Types

type Provider

type Provider interface {
	// Protect returns protected blob
	Protect(ctx context.Context, data []byte) ([]byte, error)
	// Unprotect returns unprotected data
	Unprotect(ctx context.Context, protected []byte) ([]byte, error)
	// IsReady returns true when provider has encryption keys
	IsReady() bool
	// PublicKey is returned for asymmetric signer
	PublicKey() crypto.PublicKey
}

Provider interface for data protection

func NewSymmetric

func NewSymmetric(secret []byte) (Provider, error)

NewSymmetric returns `Provider` based on AES256-GCM encryption

Jump to

Keyboard shortcuts

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