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 ¶
- func Decrypt(ciphertext interface{}, key []byte, usedBinaryData bool) ([]byte, 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)
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 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.
Types ¶
This section is empty.