crypt

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package crypt provides functions to encrypt and decrypt data using AES encryption with RSA key exchange. It uses AES-256 for symmetric encryption and RSA for asymmetric encryption. The AES key is randomly generated for each encryption operation and is encrypted with the recipient's public RSA key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(_ context.Context, pKey *rsa.PrivateKey, data, additionalData []byte) ([]byte, error)

Decrypt decrypts data that was encrypted with the Encrypt function. It uses the provided private RSA key to decrypt the AES key, and then uses that AES key to decrypt data. If data is nil or empty, nil is returned without error. The additionalData parameter should match the one used during encryption for authenticated decryption.

func Encrypt

func Encrypt(_ context.Context, pKey *rsa.PublicKey, data, additionalData []byte) ([]byte, error)

Encrypt encrypts data using AES-256 encryption with a randomly generated key. The AES key is then encrypted with the recipient's public RSA key. If data is nil or empty, nil is returned without error. The additionalData parameter can be used to provide additional authenticated data (AAD) for the encryption process.

Types

This section is empty.

Jump to

Keyboard shortcuts

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