hash

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

func Hashid

func Hashid(id uint64, minLength uint8, alphabet string) string

Hashid 使用sqids算法将数字ID编码为短哈希字符串。

参数:

  • id: 要编码的数字ID
  • minLength: 生成的哈希字符串最小长度
  • alphabet: 自定义字母表(可选)

返回值:

  • string: 编码后的哈希字符串

注意:

  • 如果编码失败返回"ERROR"
  • 默认使用sqids库的默认配置

func MapHashByte added in v1.3.2

func MapHashByte(input []byte) string

func MapHashString added in v1.3.2

func MapHashString(input string) string

func Md5Byte

func Md5Byte(in []byte, b ...byte) string

Md5Byte 计算字节切片的MD5哈希值并返回十六进制字符串。

参数:

  • in: 输入字节切片
  • b: 可选的后缀字节(可省略)

返回值:

  • string: 32字符的MD5哈希值(十六进制)

示例:

hash := Md5Byte([]byte("hello")) // 返回 "5d41402abc4b2a76b9719d911017c592"
hash := Md5Byte([]byte("hello"), '!') // 返回带后缀的哈希值

func Md5String

func Md5String(in string) string

Md5String 计算字符串的MD5哈希值并返回十六进制字符串。

参数:

  • in: 输入字符串

返回值:

  • string: 32字符的MD5哈希值(十六进制)

示例:

hash := Md5String("hello") // 返回 "5d41402abc4b2a76b9719d911017c592"

func Sha256Byte added in v1.3.2

func Sha256Byte(data []byte) string

func Sha256String added in v1.3.2

func Sha256String(data string) string

func UnHashid

func UnHashid(hashedid string, minLength uint8, alphabet string) uint64

UnHashid 解码sqids算法生成的哈希字符串为原始数字ID。

参数:

  • hashedid: 要解码的哈希字符串
  • minLength: 哈希字符串的最小长度(需与编码时一致)
  • alphabet: 自定义字母表(需与编码时一致)

返回值:

  • uint64: 解码后的数字ID

注意:

  • 如果解码失败返回0

Types

This section is empty.

Jump to

Keyboard shortcuts

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