utils

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GCMDecrypt

func GCMDecrypt(aesKey []byte, nonce []byte, ciphertext []byte) (plaintext []byte, err error)

GCMDecrypt 使用 AES-GCM 模式解密数据. 参数:

  • aesKey: AES 密钥, 支持 16, 24 或 32 字节(对应 AES-128, AES-192, AES-256).
  • nonce: 加密时生成的 nonce.
  • ciphertext: 待解密的密文.

返回值:

  • plaintext: 解密后的明文数据.
  • error: 错误信息.

func GCMDecryptWithNoncePrepended

func GCMDecryptWithNoncePrepended(aesKey []byte, ciphertext []byte) (plaintext []byte, err error)

GCMDecryptWithNoncePrepended 解密 nonce 前置的密文数据. 参数:

  • aesKey: AES 密钥, 支持 16, 24 或 32 字节(对应 AES-128, AES-192, AES-256).
  • ciphertext: nonce + 密文的组合数据.

返回值:

  • plaintext: 解密后的明文数据.
  • error: 错误信息.

func GCMEncrypt

func GCMEncrypt(aesKey []byte, plaintext []byte) (ciphertext []byte, nonce []byte, err error)

GCMEncrypt 使用 AES-GCM 模式加密数据. 参数:

  • aesKey: AES 密钥, 支持 16, 24 或 32 字节(对应 AES-128, AES-192, AES-256).
  • plaintext: 待加密的明文数据, 如果为 nil, 则返回 nil 密文和有效的 nonce.

返回值:

  • ciphertext: 加密后的密文(不包含 nonce).
  • nonce: 随机生成的 nonce(GCM 推荐 12 字节).
  • error: 错误信息.

func GCMEncryptWithNoncePrepended

func GCMEncryptWithNoncePrepended(aesKey []byte, plaintext []byte) (result []byte, nonce []byte, err error)

GCMEncryptWithNoncePrepended 使用 AES-GCM 模式加密数据, 并将 nonce 前置到密文中. 参数:

  • aesKey: AES 密钥, 支持 16, 24 或 32 字节(对应 AES-128, AES-192, AES-256).
  • plaintext: 待加密的明文数据, 如果为 nil, 则返回 nil 密文和有效的 nonce.

返回值:

  • result: nonce + 密文的组合数据.
  • nonce: 随机生成的 nonce.
  • error: 错误信息.

func GCMNonceSize

func GCMNonceSize() int

GCMNonceSize 返回 GCM 模式的 nonce 大小(通常为 12 字节).

func GenerateGCMNonce

func GenerateGCMNonce() ([]byte, error)

GenerateGCMNonce 生成一个随机的 GCM nonce. 返回值:

  • nonce: 随机生成的 nonce(12 字节).
  • error: 错误信息.

func ParseIPListFromStr

func ParseIPListFromStr(value string, delimiter string) []net.IP

ParseIPListFromStr 从逗号分隔的字符串解析 IP 地址列表.

func SplitStrTrimList

func SplitStrTrimList(value string, delimiter string) []string

SplitStrTrimList 将字符串按指定分隔符拆分为字符串切片,并去除每个元素的前后空格,忽略空元素。

Types

This section is empty.

Jump to

Keyboard shortcuts

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