Documentation
¶
Index ¶
- Constants
- func DecryptAES[T any](key string, encryptedText string) (T, error)
- func EncryptAES[T any](key string, data T) (string, error)
- type Crypto
- type CryptoAES
- type CryptoManager
- func (m *CryptoManager[T]) Decrypt(encryptedText string) (T, error)
- func (m *CryptoManager[T]) Encrypt(data T) (string, error)
- func (m *CryptoManager[T]) RegisterAesAlgorithm(version, key string) *CryptoManager[T]
- func (m *CryptoManager[T]) WithLegacyAlgo(version string) *CryptoManager[T]
- func (m *CryptoManager[T]) WithMigrationHandler(handler MigrationHandler) *CryptoManager[T]
- type CryptoRegistry
- type MigrationHandler
Constants ¶
View Source
const EncryptedPrefix = "ENC:"
EncryptedPrefix 全局前缀
Variables ¶
This section is empty.
Functions ¶
func DecryptAES ¶
DecryptAES decrypts an encrypted string into the original data type 为了向后兼容,保留此函数
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
NewAESCrypto 创建新的 AES 加密器
type CryptoAES ¶ added in v1.9.1
type CryptoAES[T any] struct { // contains filtered or unexported fields }
CryptoAES AES 加密器实现
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)
Click to show internal directories.
Click to hide internal directories.