ahash

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

README

ahash - 哈希计算库 / Hash Calculation Utilities

中文 | English


中文

📖 简介

ahash 是一个简单高效的哈希计算库,支持多种常见的哈希算法,包括 MD5、SHA1、SHA256、SHA512 和 CRC32。适用于数据校验、密码存储、文件完整性验证等场景。

GitHub地址: github.com/small-ek/antgo/crypto/ahash

📦 安装
go get github.com/small-ek/antgo/crypto/ahash
🚀 快速开始
MD5 哈希计算
package main

import (
	"fmt"
	"github.com/small-ek/antgo/crypto/ahash"
)

func main() {
	data := "需要计算哈希的数据"
	hash := ahash.MD5(data)
	fmt.Println("MD5 哈希值:", hash)
}
SHA256 哈希计算
func main() {
	data := "需要计算哈希的数据"
	hash := ahash.SHA256(data)
	fmt.Println("SHA256 哈希值:", hash)
}
CRC32 校验和计算
func main() {
	data := "需要计算校验和的数据"
	checksum := ahash.Crc32(data)
	fmt.Println("CRC32 校验和:", checksum)
}
🔧 高级用法
批量计算哈希
func main() {
	data := "批量计算哈希的数据"
	md5Hash := ahash.MD5(data)
	sha1Hash := ahash.SHA1(data)
	sha256Hash := ahash.SHA256(data)
	sha512Hash := ahash.SHA512(data)
	crc32Checksum := ahash.Crc32(data)

	fmt.Println("MD5:", md5Hash)
	fmt.Println("SHA1:", sha1Hash)
	fmt.Println("SHA256:", sha256Hash)
	fmt.Println("SHA512:", sha512Hash)
	fmt.Println("CRC32:", crc32Checksum)
}
✨ 核心特性
特性 描述
多算法支持 支持 MD5、SHA1、SHA256、SHA512 和 CRC32 等多种哈希算法
简单易用 提供简洁的 API,快速计算哈希值
高性能 基于 Go 语言原生哈希库实现,性能优异
跨平台 支持所有 Go 语言支持的平台
⚠️ 注意事项
  1. MD5 和 SHA1 已不再推荐用于密码存储等安全场景,建议使用 SHA256 或 SHA512。
  2. CRC32 主要用于校验和数据完整性验证,不适用于加密场景。
  3. 哈希值不可逆,无法从哈希值还原原始数据。
🤝 参与贡献

贡献指南 | 提交Issue


English

📖 Introduction

ahash is a simple and efficient hash calculation library supporting multiple common hash algorithms, including MD5, SHA1, SHA256, SHA512, and CRC32. It is suitable for data verification, password storage, file integrity checks, and more.

GitHub URL: github.com/small-ek/antgo/crypto/ahash

📦 Installation
go get github.com/small-ek/antgo/crypto/ahash
🚀 Quick Start
MD5 Hash Calculation
package main

import (
	"fmt"
	"github.com/small-ek/antgo/crypto/ahash"
)

func main() {
	data := "data to hash"
	hash := ahash.MD5(data)
	fmt.Println("MD5 Hash:", hash)
}
SHA256 Hash Calculation
func main() {
	data := "data to hash"
	hash := ahash.SHA256(data)
	fmt.Println("SHA256 Hash:", hash)
}
CRC32 Checksum Calculation
func main() {
	data := "data to checksum"
	checksum := ahash.Crc32(data)
	fmt.Println("CRC32 Checksum:", checksum)
}
🔧 Advanced Usage
Batch Hash Calculation
func main() {
	data := "data to hash"
	md5Hash := ahash.MD5(data)
	sha1Hash := ahash.SHA1(data)
	sha256Hash := ahash.SHA256(data)
	sha512Hash := ahash.SHA512(data)
	crc32Checksum := ahash.Crc32(data)

	fmt.Println("MD5:", md5Hash)
	fmt.Println("SHA1:", sha1Hash)
	fmt.Println("SHA256:", sha256Hash)
	fmt.Println("SHA512:", sha512Hash)
	fmt.Println("CRC32:", crc32Checksum)
}
✨ Key Features
Feature Description
Multi-algorithm Supports MD5, SHA1, SHA256, SHA512, and CRC32
Easy to Use Provides a simple API for quick hash calculation
High Performance Built on Go's native hash libraries for excellent performance
Cross-platform Supports all platforms compatible with Go
⚠️ Important Notes
  1. MD5 and SHA1 are no longer recommended for security-sensitive scenarios like password storage. Use SHA256 or SHA512 instead.
  2. CRC32 is mainly used for checksum and data integrity verification, not for encryption.
  3. Hashes are irreversible; original data cannot be restored from the hash value.
🤝 Contributing

Contribution Guide | Open an Issue

⬆ Back to Top

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CRC32 added in v1.9.4

func CRC32(data string) uint32

CRC32 computes IEEE CRC32 checksum 计算CRC32 IEEE校验值

func MD5 added in v1.8.6

func MD5(data string) string

MD5 computes the MD5 hash and returns hex-encoded string MD5哈希计算,返回十六进制编码字符串

func SHA1 added in v1.8.6

func SHA1(data string) string

SHA1 computes the SHA-1 hash and returns hex-encoded string SHA1哈希计算,返回十六进制编码字符串

func SHA256 added in v1.8.6

func SHA256(data string) string

SHA256 computes the SHA-256 hash and returns hex-encoded string SHA256哈希计算,返回十六进制编码字符串

func SHA512 added in v1.8.6

func SHA512(data string) string

SHA512 computes the SHA-512 hash and returns hex-encoded string SHA512哈希计算,返回十六进制编码字符串

func SignSHA1 added in v1.9.4

func SignSHA1(data, key string) string

SignSHA1 generates HMAC-SHA1 signature with base64 encoding

Args:

data: message to sign 待签名数据
key: secret key 密钥

Returns:

Base64-encoded signature Base64编码的签名结果

func SignSHA256 added in v1.9.4

func SignSHA256(data, key string) string

SignSHA256 generates HMAC-SHA256 signature with base64 encoding

Args:

data: message to sign 待签名数据
key: secret key 密钥

Returns:

Base64-encoded signature Base64编码的签名结果

func SignSHA512 added in v1.9.4

func SignSHA512(data, key string) string

SignSHA512 generates HMAC-SHA512 signature with base64 encoding

Args:

data: message to sign 待签名数据
key: secret key 密钥

Returns:

Base64-encoded signature Base64编码的签名结果

Types

This section is empty.

Jump to

Keyboard shortcuts

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