crypto

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 9 Imported by: 0

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 辅助函数:判断字符串是否是加密格式

func LoadOrGenerateKey

func LoadOrGenerateKey(path string) ([]byte, error)

LoadOrGenerateKey 尝试从指定路径加载密钥 如果文件不存在,会自动生成一个新的随机密钥并保存,权限设置为 0600

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