encrypt

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AesGcm added in v1.2.0

type AesGcm struct{}

AesGcm 提供AES-GCM模式的加密解密功能。 GCM(Galois/Counter Mode)提供认证加密功能。

func (*AesGcm) Decrypt added in v1.2.0

func (a *AesGcm) Decrypt(ciphertext, key, nonce []byte) ([]byte, error)

Decrypt 使用AES-GCM模式解密字节数据。

参数:

  • crypted: 加密数据(包含nonce和认证标签)
  • key: 加密密钥字节切片
  • nonceIn: 加密用的 nonce

返回值:

  • []byte: 解密后的原始数据
  • error: 解密过程中出现的错误

注意:

  • 输入数据格式应为: nonce(12字节) + 密文 + 认证标签(16字节)
  • 会验证认证标签以确保数据完整性

func (*AesGcm) Encrypt added in v1.2.0

func (a *AesGcm) Encrypt(src, key string, nonceIn []byte) (ciphertext []byte, nonce []byte, err error)

Encrypt 使用AES-GCM模式加密字符串数据。

参数:

  • src: 要加密的字符串
  • key: 加密密钥字符串
  • nonceIn: 加密用的 nonce, 如果为空, 就自动生成

返回值:

  • []byte: 加密后的数据
  • []byte: 实际使用的 nonce
  • error: 加密过程中出现的错误

注意:

  • 使用随机生成的12字节nonce
  • 认证标签长度默认为16字节
  • 返回的数据格式: nonce(12字节) + 密文 + 认证标签(16字节)

Jump to

Keyboard shortcuts

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