Files
Gogs/internal/cryptox/sha.go
ᴊᴏᴇ ᴄʜᴇɴ 36d56d5525 all: rename packages ending with "util" to end with "x" (#8182)
Co-authored-by: JSS <jss@unknwon.dev>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 13:25:19 -05:00

22 lines
434 B
Go

package cryptox
import (
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
)
// SHA1 encodes string to hexadecimal of SHA1 checksum.
func SHA1(str string) string {
h := sha1.New()
_, _ = h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
// SHA256 encodes string to hexadecimal of SHA256 checksum.
func SHA256(str string) string {
h := sha256.New()
_, _ = h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}