Files
sarffandDominik Schulz b10b940aac x3 optimization for hash (#3269)
* [fix] Fix version check (#3268)

Previously `gopass version` would always print an upgrade notice
when build from source even if there were no newer releases.

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
Signed-off-by: dmit <exehoua@gmail.com>

* x3 optimization for hash

Signed-off-by: dmit <exehoua@gmail.com>

* signed-off

Signed-off-by: dmit <exehoua@gmail.com>

---------

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
Signed-off-by: dmit <exehoua@gmail.com>
Co-authored-by: Dominik Schulz <dominik.schulz@gauner.org>
2025-10-05 20:16:33 +02:00

50 lines
1.2 KiB
Go

// Package hashsum provides hash functions for various algorithms.
package hashsum
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
"github.com/zeebo/blake3"
)
// MD5Hex returns the MD5 hash of the input string.
// Note: MD5 is cryptographically broken and should not be used for security purposes.
func MD5Hex(in string) string {
hash := md5.Sum([]byte(in))
return hex.EncodeToString(hash[:])
}
// SHA1Hex returns the SHA-1 hash of the input string.
// Note: SHA-1 is cryptographically broken and should not be used for security purposes.
func SHA1Hex(in string) string {
hash := sha1.Sum([]byte(in))
return hex.EncodeToString(hash[:])
}
// SHA256Hex returns the SHA-256 hash of the input string.
func SHA256Hex(in string) string {
hash := sha256.Sum256([]byte(in))
return hex.EncodeToString(hash[:])
}
// SHA512Hex returns the SHA-512 hash of the input string.
func SHA512Hex(in string) string {
hash := sha512.Sum512([]byte(in))
return hex.EncodeToString(hash[:])
}
// Blake3Hex returns the BLAKE3 hash of the input string.
func Blake3Hex(in string) string {
hash := blake3.Sum256([]byte(in))
return hex.EncodeToString(hash[:])
}