SHA-512 Hash Regex for Go
/^[a-f0-9]{128}$/iWhat this pattern does
This page provides a lightweight, single-purpose regular expression for matching sha-512 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
// SHA-512 Hash
// ReDoS-safe | RegexVault — Security > Password Formats
package validation
import "regexp"
var sha512HashRe = regexp.MustCompile(`^[a-f0-9]{128}$`)
func ValidateSha512Hash(s string) bool {
return sha512HashRe.MatchString(s)
}
// Example
// fmt.Println(ValidateSha512Hash("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e | cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9c |
| — | cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3eXX |
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-512 is computationally slightly faster on 64-bit systems than SHA-256 due to internal 64-bit operations. For general hashing, SHA-256 is more widely supported.
Technical Notes
SHA-512 produces 512-bit (128 hex char) digests. Part of the SHA-2 family. Commonly used for HMAC signatures, certificate fingerprints, and file integrity. For passwords, use within PBKDF2-SHA512 or Argon2.
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