encryption

package
v0.0.46 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package encryption provides functions for encrypting and decrypting data using AES-256-GCM.

Note: You MUST call InitEncryption before using any encryption functions.

Note 2: If you want to use Dislo for distributed locking, you need to call InitializeDisloLock with a valid DisloConfig. You can do this before or after Initializing encryption, but it MUST be done before you encrypt/decrypt. You can also delete a Dislo lock using DeleteDisloLock. For deletions, you can perform them any time as long as a DisloConfig is provided.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(ciphertext interface{}, key []byte, usedBinaryData bool) ([]byte, error)
Decrypt decrypts the given ciphertext using AES-256-GCM with the provided key.

The key should be 32 bytes (256 bits) for AES-256. If usedBinaryData is true, the ciphertext should be a byte slice or it will return an error. Unlike Encrypt, decrypt is going to return the plaintext as a byte slice.

func DeleteDisloLock added in v0.0.39

func DeleteDisloLock(disloConfig *DisloConfig) error

DeleteDisloLock deletes a Dislo lock for the given DisloConfig.

func Encrypt

func Encrypt(plaintext []byte, key []byte, useBinaryData bool) (interface{}, error)
Encrypt encrypts the given plaintext using AES-256-GCM with the provided key.

The key should be 32 bytes (256 bits) for AES-256. If useBinaryData is true, the ciphertext will be returned as a byte slice. The return will be in the format of string (useBinaryData = false) or []byte (useBinaryData = true). This function is probabilistic, meaning that the same plaintext and key will not always result in the same ciphertext. If you need deterministic encryption, use EncryptDeterministic instead.

func EncryptDeterministic added in v0.0.27

func EncryptDeterministic(plaintext []byte, key []byte, useBinaryData bool) (interface{}, error)

EncryptDeterministic encrypts the given plaintext using AES-256-GCM with the provided key.

This function is deterministic, meaning that the same plaintext and key will always result in the same ciphertext. If you need probabilistic encryption, use Encrypt instead.

func GenerateRandomKey added in v0.0.21

func GenerateRandomKey() ([]byte, error)

GenerateRandomKey generates a random key of the specified length. For AES-256, the length should be 32 bytes.

func InitEncryption added in v0.0.21

func InitEncryption(setNoncePoolSize int)

InitEncryption should be run before any (de)encryption operations.

func InitializeDisloLock added in v0.0.39

func InitializeDisloLock(disloConfigMap []*DisloConfig)

If you want to use Dislo for distributed locking, you need to initialize it with the DisloConfig. If you do not, local mutex will be used for locking.

Types

type DisloConfig added in v0.0.39

type DisloConfig struct {
	Host          string
	Port          int
	SkipTLS       bool
	InstanceID    int
	Namespace     string
	DisloLockID   string
	DisloClientID uuid.UUID
	EncryptionKey []byte // This is only kept locally and not used in Dislo
}

A configuration struct for using Dislo for distributed locking.

Jump to

Keyboard shortcuts

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