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.
20 lines
341 B
20 lines
341 B
|
4 years ago
|
package common
|
||
|
|
|
||
|
|
import (
|
||
|
|
"crypto/md5"
|
||
|
|
"fmt"
|
||
|
|
"main_exam_server/config"
|
||
|
|
)
|
||
|
|
|
||
|
|
func Md5(str string, key ...string) string {
|
||
|
|
key_val := config.AppConfig.AppKey
|
||
|
|
if len(key) > 0 {
|
||
|
|
key_val = key[0]
|
||
|
|
}
|
||
|
|
str = str + key_val
|
||
|
|
data := []byte(str)
|
||
|
|
has := md5.Sum(data)
|
||
|
|
md5str1 := fmt.Sprintf("%x", has) //将[]byte转成16进制
|
||
|
|
return md5str1
|
||
|
|
}
|