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.
30 lines
665 B
Go
30 lines
665 B
Go
1 year ago
|
package ncrypt
|
||
|
|
||
|
import (
|
||
|
"crypto/sha1"
|
||
|
"crypto/sha256"
|
||
|
"crypto/sha512"
|
||
|
"encoding/hex"
|
||
|
)
|
||
|
|
||
|
// Sha1 return the sha1 value (SHA-1 hash algorithm) of string.
|
||
|
func Sha1(data string) string {
|
||
|
s := sha1.New()
|
||
|
s.Write([]byte(data))
|
||
|
return hex.EncodeToString(s.Sum([]byte("")))
|
||
|
}
|
||
|
|
||
|
// Sha256 return the sha256 value (SHA256 hash algorithm) of string.
|
||
|
func Sha256(data string) string {
|
||
|
s := sha256.New()
|
||
|
s.Write([]byte(data))
|
||
|
return hex.EncodeToString(s.Sum([]byte("")))
|
||
|
}
|
||
|
|
||
|
// Sha512 return the sha512 value (SHA512 hash algorithm) of string.
|
||
|
func Sha512(data string) string {
|
||
|
s := sha512.New()
|
||
|
s.Write([]byte(data))
|
||
|
return hex.EncodeToString(s.Sum([]byte("")))
|
||
|
}
|