Text2hash-Funktion hatte gefehlt
parent
dd6a462a2f
commit
be46a99e68
@ -0,0 +1,41 @@
|
||||
package crypta
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"ebkTools"
|
||||
"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))
|
||||
|
||||
}
|
Loading…
Reference in New Issue