import ( "fmt" "github.com/docker/distribution/digest" "os" ) func main() { file, err := os.Open("file.txt") if err != nil { panic(err) } defer file.Close() sha256Digest := digest.NewDigestFromReader(digest.SHA256, file) fmt.Println(sha256Digest) }
import ( "fmt" "github.com/docker/distribution/digest" ) func main() { // create a SHA256 digest sha256Digest := digest.NewDigest(digest.SHA256, []byte("hello world")) // convert to hexadecimal format hexDigest := sha256Digest.Hex() // decode hexadecimal format back into digest value decodedDigest, err := digest.Parse(hexDigest) if err != nil { panic(err) } // compare original and decoded digest values fmt.Println(sha256Digest == decodedDigest) }This example demonstrates how to encode a digest value as a hexadecimal string using the Hex() method and how to decode a hexadecimal digest string back into its digest value using the Parse() method.