Skip to content

Hash-Sha1

Hash-Sha1 是一种产生 20 字节哈希值的哈希算法,dongle 支持标准 sha1 哈希算法,提供多种输出格式。

输入数据

go
// 输入字符串
hasher := dongle.Hash.FromString("hello world").BySha1()
// 输入字节切片
hasher := dongle.Hash.FromBytes([]byte("hello world")).BySha1()
// 输入文件流
file, _ := os.Open("test.txt")
hasher := dongle.Hash.FromFile(file).BySha1()

// 检查哈希错误
if hasher.Error != nil {
	fmt.Printf("哈希错误: %v\n", hasher.Error)
	return
}

输出数据

go
// 输出 Hex 编码字符串
hasher.ToHexString() // 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
// 输出 Hex 编码字节切片
hasher.ToHexBytes()  // []byte("2aae6c35c94fcfb415dbe95f408b9ce91ee846ed")

// 输出 Base64 编码字符串
hasher.ToBase64String() // Kq5sNclPz7QV2+lfQIuc6R7oRu0=
// 输出 Base64 编码字节切片
hasher.ToBase64Bytes()  // []byte("Kq5sNclPz7QV2+lfQIuc6R7oRu0=")

// 输出 原始 字符串
hasher.ToRawString()
// 输出 原始 字节切片
hasher.ToRawBytes()

基于 MIT 许可发布,未经许可禁止任何形式的转载