util

package
v0.0.0-...-a29d1be Latest Latest
Warning

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

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

Documentation

Overview

util 工具包 收纳一些基础性的工具函数。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(data []byte, key *[32]byte) ([]byte, error)

Decrypt 使用 256 位 AES-GCM 解密数据。 该加密算法既对数据实施了加密,同时也提供了数据完整性检查。 参考:github.com/gtank/cryptopasta @data 已加密数据的密文 @key 一个32字节长密钥的指针 @return 已解密的明文

func Encrypt

func Encrypt(text []byte, key *[32]byte) ([]byte, error)

Encrypt 使用 256 位 AES-GCM 加密数据。 该加密算法既对数据实施了加密,同时也提供了数据完整性检查。 注意 nonce 前置在了密文头部。 参考:github.com/gtank/cryptopasta @text 待加密的明文数据 @key 一个32字节长密钥的指针 @return 密文(含前置nonce)

func GenerateToken

func GenerateToken(size int) ([]byte, error)

GenerateToken 生成一个随机字节序列。 @size 目标长度(字节数)

func Hash384

func Hash384(data []byte, ip netip.Addr) [48]byte

Hash384 创建融入IP的SHA-384哈希值。 注意:此函数与HashMAC_ip不同,它不使用HMAC,而是直接串接计算。 @data 目标数据,哈希的内容。 @ip 目标IP地址,会剥离IPv4嵌入以容错混用。 @return 返回48字节的SHA-384哈希值。

func HashMAC_ip

func HashMAC_ip(data []byte, ip netip.Addr) [48]byte

HashMAC 创建融入IP的哈希消息码。 @data 目标数据,哈希的内容。 @ip 目标IP地址,会剥离IPv4嵌入以容错混用。

Types

This section is empty.

Directories

Path Synopsis
Package selfsign is a test helper that generates self signed certificate.
Package selfsign is a test helper that generates self signed certificate.