REGEXVAULTv2.0
Security/Password Formats
Verified Safe

SHA-256 Hash Regex for Go

/^[a-f0-9]{64}$/i

What this pattern does

This page provides a lightweight, single-purpose regular expression for matching sha-256 hash, ported and verified for Go. In security-sensitive code, using an unverified regex can open the door to both false positives and denial-of-service attacks. The snippet below is ready to drop into your Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.

Go Implementation

Go
// SHA-256 Hash
// ReDoS-safe | RegexVault — Security > Password Formats

package validation

import "regexp"

var sha256HashRe = regexp.MustCompile(`^[a-f0-9]{64}$`)

func ValidateSha256Hash(s string) bool {
    return sha256HashRe.MatchString(s)
}

// Example
// fmt.Println(ValidateSha256Hash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855X

When to use this pattern

This pattern is drawn from the Security > Password Formats category and carries a ReDoS-safe certification. That matters for Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

SHA-256 of a password without salt is equivalent to MD5 for dictionary attacks — it is fast to compute and has no iteration cost. Always use a proper KDF (Key Derivation Function) for password storage.

Technical Notes

SHA-256 is part of the SHA-2 family, still cryptographically secure. Used for certificates, code signing, TLS, and file integrity. For password hashing, always use SHA-256 within a proper password hashing function (PBKDF2, Argon2) — raw SHA-256 alone is not suitable for passwords.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern