DevToolsForYou

Hash Generator in Go — Code Examples

Hash Generator in GoUse the online tool →

Cryptographic hash functions convert input data into a fixed-size digest. SHA-256 is the current standard for security-sensitive use cases; MD5 is broken for security but still used for checksums.

Go's crypto package includes sha256, sha512, md5, and others. All implement the hash.Hash interface.

Go
package main

import (
    "crypto/md5"
    "crypto/sha256"
    "crypto/sha512"
    "crypto/hmac"
    "fmt"
)

func main() {
    input := []byte("Hello, world!")

    // SHA-256
    h256 := sha256.Sum256(input)
    fmt.Printf("%x
", h256)
    // 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3

    // SHA-512
    h512 := sha512.Sum512(input)
    fmt.Printf("%x
", h512)

    // MD5 (checksums only)
    hMd5 := md5.Sum(input)
    fmt.Printf("%x
", hMd5)

    // HMAC-SHA256
    mac := hmac.New(sha256.New, []byte("secret-key"))
    mac.Write(input)
    fmt.Printf("%x
", mac.Sum(nil))
}
Notes & gotchas
  • sha256.Sum256() returns a [32]byte array — use fmt.Sprintf("%x", h) to get the hex string.
  • For streaming large inputs, use sha256.New() and write chunks with h.Write().
  • Go's crypto/hmac implements constant-time comparison — use hmac.Equal() to compare MACs.
Try it in your browser

Need to hash md5/sha without writing code? The Hash Generator runs entirely in your browser — paste your input and get the result instantly. No signup, no install, no data sent to a server.

Open Hash MD5/SHA
Hash Generator in other languages