encryption

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 11 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.

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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