You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.1 KiB
Go
63 lines
1.1 KiB
Go
8 months ago
|
package starcrypto
|
||
|
|
||
|
import (
|
||
|
"crypto/sha1"
|
||
|
"crypto/sha256"
|
||
|
"crypto/sha512"
|
||
|
)
|
||
|
|
||
|
// SHA512 输出SHA512校验值
|
||
|
func Sha512(bstr []byte) []byte {
|
||
|
shasum := sha512.New()
|
||
|
shasum.Write(bstr)
|
||
|
return shasum.Sum(nil)
|
||
|
}
|
||
|
|
||
|
func Sha512Str(bstr []byte) string {
|
||
|
return String(Sha512(bstr))
|
||
|
}
|
||
|
|
||
|
// SHA384 输出SHA384校验值
|
||
|
func Sha384(bstr []byte) []byte {
|
||
|
shasum := sha512.New384()
|
||
|
shasum.Write(bstr)
|
||
|
return shasum.Sum(nil)
|
||
|
}
|
||
|
|
||
|
func Sha384Str(bstr []byte) string {
|
||
|
return String(Sha384(bstr))
|
||
|
}
|
||
|
|
||
|
// SHA256 输出SHA256校验值
|
||
|
func Sha256(bstr []byte) []byte {
|
||
|
shasum := sha256.New()
|
||
|
shasum.Write(bstr)
|
||
|
return shasum.Sum(nil)
|
||
|
}
|
||
|
|
||
|
func Sha256Str(bstr []byte) string {
|
||
|
return String(Sha256(bstr))
|
||
|
}
|
||
|
|
||
|
// SHA224 输出SHA224校验值
|
||
|
func Sha224(bstr []byte) []byte {
|
||
|
shasum := sha256.New224()
|
||
|
shasum.Write(bstr)
|
||
|
return shasum.Sum(nil)
|
||
|
}
|
||
|
|
||
|
func Sha224Str(bstr []byte) string {
|
||
|
return String(Sha224(bstr))
|
||
|
}
|
||
|
|
||
|
// SHA1 输出SHA1校验值
|
||
|
func Sha1(bstr []byte) []byte {
|
||
|
shasum := sha1.New()
|
||
|
shasum.Write(bstr)
|
||
|
return shasum.Sum(nil)
|
||
|
}
|
||
|
|
||
|
func Sha1Str(bstr []byte) string {
|
||
|
return String(Sha512(bstr))
|
||
|
}
|