添加更多的方法

This commit is contained in:
yun
2025-11-03 23:40:41 +08:00
parent 6e088f68bd
commit 7bbd570de9
10 changed files with 1660 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
package sha3x
import (
"encoding/hex"
"golang.org/x/crypto/sha3"
)
// SHA3-256 哈希
func Sha3_256(src string) string {
h := sha3.New256()
h.Write([]byte(src))
return hex.EncodeToString(h.Sum(nil))
}
// SHA3-384 哈希
func Sha3_384(src string) string {
h := sha3.New384()
h.Write([]byte(src))
return hex.EncodeToString(h.Sum(nil))
}
// SHA3-512 哈希
func Sha3_512(src string) string {
h := sha3.New512()
h.Write([]byte(src))
return hex.EncodeToString(h.Sum(nil))
}
// SHAKE128 可变长度哈希
func Shake128(src string, outputLength int) string {
h := sha3.NewShake128()
h.Write([]byte(src))
output := make([]byte, outputLength)
h.Read(output)
return hex.EncodeToString(output)
}
// SHAKE256 可变长度哈希
func Shake256(src string, outputLength int) string {
h := sha3.NewShake256()
h.Write([]byte(src))
output := make([]byte, outputLength)
h.Read(output)
return hex.EncodeToString(output)
}