codec

package
v0.0.0-...-656b6e9 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base32Decode

func Base32Decode(encoded string) ([]byte, error)

func Base32Encode

func Base32Encode(data []byte) string

func Base64Decode

func Base64Decode(encoded string) ([]byte, error)

func Base64Encode

func Base64Encode(data []byte) string

func CompressRatio

func CompressRatio(original, compressed []byte) float64

CompressRatio 计算压缩比率(原始大小 / 压缩后大小)

func GZipDecode

func GZipDecode(input []byte) ([]byte, error)

GZipDecode 解压 gzip 格式的数据

func GZipEncode

func GZipEncode(input []byte, level ...int) ([]byte, error)

GZipEncode 压缩数据到 gzip 格式 支持可选的压缩级别配置

func GzipDecodeString

func GzipDecodeString(input []byte) (string, error)

GzipDecodeString 解压 gzip 数据到字符串

func GzipEncodeString

func GzipEncodeString(input string, level ...int) ([]byte, error)

GzipEncodeString 压缩字符串到 gzip 格式

func IsGzipData

func IsGzipData(data []byte) bool

IsGzipData 检查数据是否为有效的 gzip 格式

func MD5

func MD5(data []byte) string

MD5 计算数据的MD5哈希值

func MD5String

func MD5String(s string) string

MD5String 计算字符串的MD5哈希值

func NewAESCipher

func NewAESCipher(key string, cipherType AESCipherType) (*aesCipher, error)

* AES 中的 128、192、256 主要是根据密钥长度来区分的,这是三者最核心的区别。具体对应关系如下:

AES-128:使用 128 位(16 字节)的密钥 AES-192:使用 192 位(24 字节)的密钥 AES-256:使用 256 位(32 字节)的密钥

除了密钥长度不同,三者的加密轮数也不同(轮数越多,加密过程越复杂):

AES-128:10 轮加密 AES-192:12 轮加密 AES-256:14 轮加密 * NewAESCipher 创建AES加密器

func SHA1

func SHA1(data []byte) string

SHA1 计算数据的SHA1哈希值

func SHA1String

func SHA1String(s string) string

SHA1String 计算字符串的SHA1哈希值

func SHA224

func SHA224(data []byte) string

SHA224 计算数据的SHA224哈希值

func SHA224String

func SHA224String(s string) string

SHA224String 计算字符串的SHA224哈希值

func SHA256

func SHA256(data []byte) string

SHA256 计算数据的SHA256哈希值

func SHA256String

func SHA256String(s string) string

SHA256String 计算字符串的SHA256哈希值

func SHA384

func SHA384(data []byte) string

SHA384 计算数据的SHA384哈希值

func SHA384String

func SHA384String(s string) string

SHA384String 计算字符串的SHA384哈希值

func SHA512

func SHA512(data []byte) string

SHA512 计算数据的SHA512哈希值

func SHA512String

func SHA512String(s string) string

SHA512String 计算字符串的SHA512哈希值

func SHA512_224

func SHA512_224(data []byte) string

SHA512_224 计算数据的SHA512/224哈希值

func SHA512_224String

func SHA512_224String(s string) string

SHA512_224String 计算字符串的SHA512/224哈希值

func SHA512_256

func SHA512_256(data []byte) string

SHA512_256 计算数据的SHA512/256哈希值

func SHA512_256String

func SHA512_256String(s string) string

SHA512_256String 计算字符串的SHA512/256哈希值

Types

type AESCipherType

type AESCipherType int
const (
	GCM AESCipherType = iota
	CBC
	CTR
)

type CodecAES

type CodecAES interface {
	Encrypt(plaintext []byte) ([]byte, error)
	Decrypt(ciphertext []byte) ([]byte, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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