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 ¶
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 ¶
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