package utils

import (
	"encoding/base64"
	"strings"

)

func Base64Encode(data []byte) string {
	return base64.StdEncoding.EncodeToString(data)
}

func Base64Decode(data string) string {
	b, err := base64.StdEncoding.DecodeString(data)
	if err != nil {
		return ""
	}
	return string(b)
}

//校验加密串
func ValidSecretKey(secStr string) bool {
	if !strings.HasPrefix(secStr, "CE:") || len(secStr) < 35 {
		return false
	}

	clientMd5Key := secStr[3:35]
	rawmsg := secStr[35:]
	// log.Debugf("data base: %s", rawmsg)
	serverMd5Key := MD5Str(rawmsg) //这里可以再加上客户端和服务端的秘钥再MD5
	return strings.EqualFold(strings.ToLower(serverMd5Key), strings.ToLower(clientMd5Key))
}
