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.
51 lines
1.4 KiB
51 lines
1.4 KiB
/**
|
|
= Creative Commons Lizenzvertrag =
|
|
ebktools von der archium GmbH, Gera ist lizenziert unter einer Creative Commons Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International Lizenz. (http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de)
|
|
Individuelle über diese Lizenz hinausgehende Berechtigungen können Sie unter https://archium.org erhalten.
|
|
|
|
= Creative Commons License =
|
|
ebktools by archium GmbH, Gera is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. (http://creativecommons.org/licenses/by-nc-nd/4.0/)
|
|
Individual permissions beyond the scope of this license may be available at https://archium.org.
|
|
**/
|
|
package crypta
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"crypto/sha256"
|
|
"crypto/sha512"
|
|
"fmt"
|
|
"hash"
|
|
|
|
"git.archium.org/archium_public/ebkTools"
|
|
)
|
|
|
|
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))
|
|
|
|
}
|
|
|