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 ¶
- func Decrypt(ciphertext interface{}, key []byte, usedBinaryData bool) ([]byte, error)
- func DeleteDisloLock(disloConfig *DisloConfig) error
- func Encrypt(plaintext []byte, key []byte, useBinaryData bool) (interface{}, error)
- func EncryptDeterministic(plaintext []byte, key []byte, useBinaryData bool) (interface{}, error)
- func GenerateRandomKey() ([]byte, error)
- func InitEncryption(setNoncePoolSize int)
- func InitializeDisloLock(disloConfigMap []*DisloConfig)
- type DisloConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
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 ¶
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
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
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.