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.

52 lines
843 B
Go

package certs
import (
"bytes"
"crypto/md5"
"encoding/hex"
"math/rand"
)
const (
allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
allowedCharsSize = len(allowedChars)
)
// returns a securely generated random string.
func randomString(length int) string {
b := make([]byte, length)
for i := range b {
c := rand.Intn(allowedCharsSize)
b[i] = allowedChars[c]
}
return string(b)
}
func mmd5(str string) string {
var buf = bytes.NewBufferString(str)
hash := md5.New()
hash.Write(buf.Bytes())
sign := hash.Sum(nil)
return hex.EncodeToString(sign)
}
func checkHeaderSign(header map[string]interface{}) (slt, sin string, ok bool) {
salt, ok := header[saltKey]
if !ok {
return
}
sign, ok := header[signKey]
if !ok {
return
}
slt, sin = salt.(string), sign.(string)
return
}