Some tools, I frequently use.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
711 B

package crypta
import (
"PinGo/ebkTools"
"crypto/md5"
"crypto/sha256"
"crypto/sha512"
"fmt"
"hash"
)
type (
cryptaType string
)
const (
CRYPTA_MD5 cryptaType = "md5"
CRYPTA_SHA256 cryptaType = "sha256"
CRYPTA_SHA512 cryptaType = "sha512"
)
//Text2hash wandelt einen String in einen Hash um
func Text2hash(s string, enc cryptaType) (h string) {
var myHash hash.Hash
switch enc {
default: // md5 is default
myHash = md5.New()
case CRYPTA_MD5:
myHash = md5.New()
case CRYPTA_SHA256:
myHash = sha256.New()
case CRYPTA_SHA512:
myHash = sha512.New()
}
_, err := myHash.Write([]byte(s))
ebkTools.Check(err)
//
return fmt.Sprintf("%x", myHash.Sum(nil)) //string(myHash.Sum(nil))
}