crypto

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package crypto provides encryption and decryption utilities using AES-GCM. AES-GCM is an authenticated encryption scheme that provides both confidentiality and integrity protection.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKeySize   = errors.New("crypto: key must be 16, 24, or 32 bytes for AES-128, AES-192, or AES-256")
	ErrCiphertextShort  = errors.New("crypto: ciphertext too short")
	ErrDecryptionFailed = errors.New("crypto: decryption failed")
)

Functions

func AESDecrypt

func AESDecrypt(key, ciphertext []byte) ([]byte, error)

AESDecrypt decrypts ciphertext that was encrypted with AESEncrypt. Expects the nonce to be prepended to the ciphertext.

func AESDecryptString

func AESDecryptString(key []byte, encoded string) (string, error)

AESDecryptString decrypts a base64-encoded ciphertext string.

func AESEncrypt

func AESEncrypt(key, plaintext []byte) ([]byte, error)

AESEncrypt encrypts plaintext using AES-GCM with the given key. The key must be 16, 24, or 32 bytes long (AES-128, AES-192, AES-256). Returns the nonce prepended to the ciphertext.

func AESEncryptString

func AESEncryptString(key []byte, plaintext string) (string, error)

AESEncryptString encrypts a plaintext string and returns a base64-encoded ciphertext.

func GenerateAESKey

func GenerateAESKey(size int) ([]byte, error)

GenerateAESKey generates a random AES key of the specified byte size. Valid sizes are 16 (AES-128), 24 (AES-192), or 32 (AES-256).

Types

This section is empty.

Jump to

Keyboard shortcuts

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