import "github.com/coreos/rkt/pkg/crypto" hashBytes := crypto.SHA256([]byte("hello world")) hashString := types.HashString(hashBytes).String() fmt.Println(hashString)
sha256-2ef7bde608ce5404e97d5f042f95f89f1c232871a9ba923cbf
hashString := "sha256-2ef7bde608ce5404e97d5f042f95f89f1c232871a9ba923cbf" hash, err := types.NewHashString(hashString) if err != nil { fmt.Println("Invalid hash string") } else { fmt.Println("Valid hash:", hash.String()) }
Valid hash: sha256-2ef7bde608ce5404e97d5f042f95f89f1c232871a9ba923cbfBoth examples use the HashString data type provided by the appc/spec/schema/types package from the CoreOS rkt repository in GitHub. The first example creates a SHA256 hash string using the crypto package from the same repository. The second example validates a hash string and demonstrates the use of the NewHashString constructor.