encrypt

package
v1.91.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package encrypt contains a collection of utility functions to encrypt and decrypt data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteDecryptAny

func ByteDecryptAny(key, msg []byte, data any) error

ByteDecryptAny decrypts a byte-slice message produced with the ByteEncryptAny function to the provided data object. The value underlying data must be a pointer to the correct type for the next data item received. The key argument must be the same used to encrypt the data: either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.

func ByteDecryptSerializeAny

func ByteDecryptSerializeAny(key, msg []byte, data any) error

ByteDecryptSerializeAny decrypts a byte-slice message produced with the ByteEncryptSerializeAny function to the provided data object. The value underlying data must be a pointer to the correct type for the next data item received. The key argument must be the same used to encrypt the data: either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.

func ByteEncryptAny

func ByteEncryptAny(key []byte, data any) ([]byte, error)

ByteEncryptAny encrypts the input data with the specified key and returns a base64 byte slice. The input data is serialized using gob, encrypted with the Encrypt method and encoded as base64. The key argument must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.

func ByteEncryptSerializeAny

func ByteEncryptSerializeAny(key []byte, data any) ([]byte, error)

ByteEncryptSerializeAny encrypts the input data with the specified key and returns a base64 byte slice. The input data is serialized using json, encrypted with the Encrypt method and encoded as base64. The key argument must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.

func Decrypt

func Decrypt(key, msg []byte) ([]byte, error)

Decrypt decrypts a byte-slice data encrypted with the Encrypt function. The key argument must be the same used to encrypt the data: either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.

func DecryptAny

func DecryptAny(key []byte, msg string, data any) error

DecryptAny wraps the ByteDecryptAny function to accept a msg string instead of a byte slice.

func DecryptSerializeAny

func DecryptSerializeAny(key []byte, msg string, data any) error

DecryptSerializeAny wraps the ByteDecryptSerializeAny function to accept a msg string instead of a byte slice.

func Encrypt

func Encrypt(key, msg []byte) ([]byte, error)

Encrypt encrypts the byte-slice input msg with the specified key. The key argument must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.

func EncryptAny

func EncryptAny(key []byte, data any) (string, error)

EncryptAny wraps the ByteEncryptAny function to return a string instead of a byte slice.

func EncryptSerializeAny

func EncryptSerializeAny(key []byte, data any) (string, error)

EncryptSerializeAny wraps the ByteEncrypSerializetAny function to return a string instead of a byte slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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