Created
January 27, 2019 07:36
-
-
Save ik5/466308c733567ba3f57ad693648dd8bb to your computer and use it in GitHub Desktop.
example of using golang's sha512 for checksum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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