aes

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

README

pki/aes

Import path: github.com/InsideGallery/core/pki/aes

pki/aes is the legacy AES-GCM cipher package. New code should prefer github.com/InsideGallery/core/pki/aesgcm, which re-exports this behavior under an algorithm-specific package name that does not collide with crypto/aes.

Main API

  • AES implements the pki.Cipher interface.
  • NewAES(size) and NewAESStrict(size) create a cipher with a random key.
  • AES16, AES24, and AES32 are the supported key sizes in bytes.
  • ErrInvalidAESSize reports unsupported key sizes.
  • Kind() returns "aes".
  • Encrypt(plaintext) encrypts with AES-GCM, prefixes a random nonce to the ciphertext, and returns the nonce plus ciphertext as hex-encoded bytes.
  • Decrypt(ciphertext) expects the hex-encoded format returned by Encrypt.
  • ToBinary() returns the raw key bytes.
  • FromBinary(raw) restores a cipher from raw key bytes.

Usage

package example

import coreaes "github.com/InsideGallery/core/pki/aes"

func encrypt(plaintext []byte) ([]byte, []byte, error) {
	cipher, err := coreaes.NewAES(coreaes.AES32)
	if err != nil {
		return nil, nil, err
	}

	key, err := cipher.ToBinary()
	if err != nil {
		return nil, nil, err
	}

	ciphertext, err := cipher.Encrypt(plaintext)
	if err != nil {
		return nil, nil, err
	}

	return ciphertext, key, nil
}

Security and Compatibility Notes

AES-GCM encryption uses a random nonce and no additional authenticated data. ToBinary exposes raw key material; store it only in a suitable secret store. FromBinary accepts any byte slice and leaves invalid key sizes to fail during encrypt or decrypt calls. This package remains for compatibility; prefer pki/aesgcm for new code.

Documentation

Overview

Package aes is the legacy AES-GCM import path.

New code should import the focused replacement package:

import "github.com/InsideGallery/core/pki/aesgcm"

Compatibility: existing AES-GCM exports remain available for downstream consumers that still import pki/aes. Do not add new helpers here; add AES-GCM behavior to pki/aesgcm so call sites avoid a local name collision with crypto/aes.

Index

Constants

View Source
const (
	AES32 = 32
	AES24 = 24
	AES16 = 16
)

Variables

View Source
var ErrInvalidAESSize = errors.New("invalid AES key size, must be 16, 24, or 32")

Functions

This section is empty.

Types

type AES

type AES struct {
	// contains filtered or unexported fields
}

func NewAES

func NewAES(size int) (*AES, error)

func NewAESStrict added in v1.1.0

func NewAESStrict(size int) (*AES, error)

func (*AES) Decrypt

func (a *AES) Decrypt(encrypted []byte) ([]byte, error)

func (*AES) Encrypt

func (a *AES) Encrypt(origin []byte) ([]byte, error)

func (*AES) FromBinary

func (a *AES) FromBinary(raw []byte) (localCipher.Cipher, error)

func (*AES) Kind

func (a *AES) Kind() string

func (*AES) ToBinary

func (a *AES) ToBinary() ([]byte, error)

Jump to

Keyboard shortcuts

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