Skip to content

Instantly share code, notes, and snippets.

@ik5
Created January 27, 2019 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ik5/466308c733567ba3f57ad693648dd8bb to your computer and use it in GitHub Desktop.
Save ik5/466308c733567ba3f57ad693648dd8bb to your computer and use it in GitHub Desktop.
example of using golang's sha512 for checksum
package main
import (
"crypto/sha512"
"fmt"
)
// CalcChecksum takes a slice of bytes and calculate it as a checksum
// it is using SHA512 for that (128 bytes for result)
func CalcChecksum(buff []byte) []byte {
sha := sha512.New()
sha.Write(buff)
checksum := sha.Sum(nil)
return checksum
}
func main() {
// calc "a"
calcHex := fmt.Sprintf("%x", CalcChecksum([]byte{97}))
hex := "1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75"
fmt.Println(calcHex == hex, len(hex))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment