添加更多的方法
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user