crypto

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

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 KeySize = 32 // AES-256 需要 32 字节密钥
View Source
const (
	// Prefix 用于标识加密字段的前缀,方便配置文件解析
	Prefix = "ENC:"
)

Variables

This section is empty.

Functions

func IsEncrypted

func IsEncrypted(s string) bool

IsEncrypted 辅助函数:判断字符串是否是加密格式

Types

type Crypter

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

Crypter 封装了 AES-GCM 的操作

func NewCrypter

func NewCrypter(key []byte) (*Crypter, error)

NewCrypter 创建一个新的加解密实例 key 必须是 32 字节 (AES-256)

func (*Crypter) Decrypt

func (c *Crypter) Decrypt(encoded string) (string, error)

Decrypt 解密字符串 输入格式必须以 ENC: 开头

func (*Crypter) Encrypt

func (c *Crypter) Encrypt(plaintext string) (string, error)

Encrypt 加密字符串 输出格式: ENC:<Base64(Nonce + Ciphertext)>

Jump to

Keyboard shortcuts

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