cryptox

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: MIT Imports: 9 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const EncryptedPrefix = "ENC:"

EncryptedPrefix 全局前缀

Variables

This section is empty.

Functions

func DecryptAES

func DecryptAES[T any](key string, encryptedText string) (T, error)

DecryptAES decrypts an encrypted string into the original data type 为了向后兼容,保留此函数

func EncryptAES

func EncryptAES[T any](key string, data T) (string, error)

EncryptAES encrypts any data type using a given key 为了向后兼容,保留此函数

Types

type Crypto added in v1.9.1

type Crypto[T any] interface {
	// Encrypt 加密任意类型的数据
	Encrypt(data T) (string, error)

	// Decrypt 解密数据到指定类型
	Decrypt(encryptedText string) (T, error)
}

Crypto 定义加密解密接口

func NewAESCrypto added in v1.9.1

func NewAESCrypto[T any](key string) Crypto[T]

NewAESCrypto 创建新的 AES 加密器

type CryptoAES added in v1.9.1

type CryptoAES[T any] struct {
	// contains filtered or unexported fields
}

CryptoAES AES 加密器实现

func (*CryptoAES[T]) Decrypt added in v1.9.1

func (a *CryptoAES[T]) Decrypt(encryptedText string) (T, error)

Decrypt 解密数据到指定类型

func (*CryptoAES[T]) Encrypt added in v1.9.1

func (a *CryptoAES[T]) Encrypt(data T) (string, error)

Encrypt 加密任意类型的数据

type CryptoManager added in v1.9.1

type CryptoManager[T any] struct {
	// contains filtered or unexported fields
}

CryptoManager 统一管理多种加密算法(支持多版本)

func NewCryptoManager added in v1.9.1

func NewCryptoManager[T any](defaultVer string) *CryptoManager[T]

NewCryptoManager 创建新的 CryptoManager

func (*CryptoManager[T]) Decrypt added in v1.9.1

func (m *CryptoManager[T]) Decrypt(encryptedText string) (T, error)

Decrypt 解密(自动识别版本,兼容历史数据)

func (*CryptoManager[T]) Encrypt added in v1.9.1

func (m *CryptoManager[T]) Encrypt(data T) (string, error)

Encrypt 加密(幂等,避免重复加密) 自动给旧数据加上 ENC:<version>: 前缀

func (*CryptoManager[T]) RegisterAesAlgorithm added in v1.9.1

func (m *CryptoManager[T]) RegisterAesAlgorithm(version, key string) *CryptoManager[T]

RegisterAesAlgorithm 注册 AES 算法,带版本号

func (*CryptoManager[T]) WithLegacyAlgo added in v1.9.1

func (m *CryptoManager[T]) WithLegacyAlgo(version string) *CryptoManager[T]

WithLegacyAlgo 设置历史兼容算法(老数据没加 ENC: 前缀时使用)

func (*CryptoManager[T]) WithMigrationHandler added in v1.9.1

func (m *CryptoManager[T]) WithMigrationHandler(handler MigrationHandler) *CryptoManager[T]

WithMigrationHandler 设置迁移回调

type CryptoRegistry added in v1.9.1

type CryptoRegistry struct {
	User     *CryptoManager[string]
	Resource *CryptoManager[string]
	Runner   *CryptoManager[string]
}

type MigrationHandler added in v1.9.1

type MigrationHandler func(oldEnc, newEnc string)

Jump to

Keyboard shortcuts

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