Search code examples
arraysgochecksum

checksum of a byte array


I have a []byte, made from a string:

    array := []byte("some string")

It looks like expected:

    [115 111 109 101 32 115 116 114 105 110 103]

Is there a way to simply get the checksum of []byte? Like:

    sum(array)

Solution

  • Maybe you need md5.sum to check reliability.

    https://pkg.go.dev/crypto/md5#Sum

    package main
    
    import (
        "crypto/md5"
        "fmt"
    )
    
    func main() {
        data := []byte("some string")
        fmt.Printf("%x", md5.Sum(data))
    }
    

    Another example.

    https://play.golang.org/p/7_ctunsqHS3