jsonencryption

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package jsonencryption provides a simple way to handle encryption and decryption of JSON data, particularly useful for database interactions. It introduces EncryptedID, a type designed to replace auto-incrementing primary keys in databases with an encrypted form in JSON, enhancing data privacy and security.

Key Features: - EncryptedID: A struct type to represent encrypted database primary keys. - Encryption and Decryption: Functions to convert between encrypted and plain data. - Hashing and Masking: Tools to hash and mask uint values for additional security.

Usage involves setting a 16-byte encryption key and utilizing the provided methods to encrypt JSON data structures, primarily focusing on the primary key fields. EncryptedID can be seamlessly integrated into database models and JSON serialization, ensuring that sensitive integer IDs are not exposed in API responses.

The package also includes functions for hashing and masking uints, useful for creating non-reversible identifiers or temporary masked values for secure data handling.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKey = errors.New("invalid key, it must be 16 bytes long")
	ErrNoSecret   = errors.New("secret object is nil, you must call SetKey() first")
)

Functions

func Hash

func Hash(input uint) string

func SetKey

func SetKey(key string)

Types

type EncryptedID

type EncryptedID struct {
	Val uint
}

func NewEncryptedID

func NewEncryptedID(val uint) EncryptedID

func (EncryptedID) MarshalJSON

func (i EncryptedID) MarshalJSON() ([]byte, error)

func (*EncryptedID) Scan

func (i *EncryptedID) Scan(value interface{}) error

func (EncryptedID) ToInt

func (i EncryptedID) ToInt() int

func (EncryptedID) ToMasked

func (i EncryptedID) ToMasked() string

func (EncryptedID) ToString

func (i EncryptedID) ToString() string

func (EncryptedID) Value

func (i EncryptedID) Value() (driver.Value, error)

type Secret

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

func NewSecret

func NewSecret(maskSecret string) *Secret

func (Secret) Mask

func (e Secret) Mask(id uint) (string, error)

func (Secret) Unmask

func (e Secret) Unmask(ciphertext string) (uint, error)

Jump to

Keyboard shortcuts

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