Skip to content

Commit

Permalink
add hashes bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
qwenode committed Apr 23, 2024
1 parent 6862ee5 commit 358042e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
7 changes: 6 additions & 1 deletion hashes/crc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import (

// Crc32 get string crc32 hash
func Crc32(str string) string {
return Crc32Byte([]byte(str))
}

// Crc32Byte get byte crc32 hash
func Crc32Byte(data []byte) string {
table := crc32.MakeTable(crc32.IEEE)
byteString := crc32.Checksum([]byte(str), table)
byteString := crc32.Checksum(data, table)
return fmt.Sprintf("%x", byteString)
}
7 changes: 6 additions & 1 deletion hashes/md5.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ import (

// Md5 get string md5 hash
func Md5(str string) string {
return fmt.Sprintf("%x", md52.Sum([]byte(str)))
return Md5Byte([]byte(str))
}

// Md5Byte get byte md5 hash
func Md5Byte(data []byte) string {
return fmt.Sprintf("%x", md52.Sum(data))
}
21 changes: 18 additions & 3 deletions hashes/sha.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,30 @@ import (

// Sha1 get string sha1 hash
func Sha1(str string) string {
return fmt.Sprintf("%x", sha12.Sum([]byte(str)))
return Sha1Byte([]byte(str))
}

// Sha1Byte get byte sha1 hash
func Sha1Byte(data []byte) string {
return fmt.Sprintf("%x", sha12.Sum(data))
}

// Sha256 get string sha256 hash
func Sha256(str string) string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(str)))
return Sha256Byte([]byte(str))
}

// Sha256Byte get bytes sha256 hash
func Sha256Byte(data []byte) string {
return fmt.Sprintf("%x", sha256.Sum256(data))
}

// Sha512 get string sha512 hash
func Sha512(str string) string {
return fmt.Sprintf("%x", sha512.Sum512([]byte(str)))
return Sha1Byte([]byte(str))
}

// Sha512Byte get bytes sha512 hash
func Sha512Byte(data []byte) string {
return fmt.Sprintf("%x", sha512.Sum512(data))
}

0 comments on commit 358042e

Please sign in to comment.