hsun 1 жил өмнө
parent
commit
67701bfdd7

+ 1 - 1
controller/resp/base.go

@@ -50,7 +50,7 @@ func result(code int, resultData ResultData, c *gin.Context) {
 		c.JSON(code, resultData)
 	} else {
 		global.LOG.Info(strings.Join(logSlice, ";"))
-		encryptResult := utils.DesBase64Encrypt(jsonByte)
+		encryptResult := utils.DesBase64Encrypt(jsonByte, global.CONFIG.Serve.DesKey)
 		c.JSON(code, string(encryptResult))
 	}
 	c.Abort()

+ 4 - 8
utils/des3.go

@@ -11,20 +11,16 @@ import (
 	"strings"
 )
 
-const (
-	key = "6WpHp4vSvLVQK8SLioNZ7WMq"
-)
-
 // des3 + base64 encrypt
-func DesBase64Encrypt(origData []byte) []byte {
-	result, err := TripleDesEncrypt(origData, []byte(key))
+func DesBase64Encrypt(origData []byte, desKey string) []byte {
+	result, err := TripleDesEncrypt(origData, []byte(desKey))
 	if err != nil {
 		panic(err)
 	}
 	return []byte(base64.StdEncoding.EncodeToString(result))
 }
 
-func DesBase64Decrypt(crypted []byte) []byte {
+func DesBase64Decrypt(crypted []byte, desKey string) []byte {
 	result, _ := base64.StdEncoding.DecodeString(string(crypted))
 	remain := len(result) % 8
 	if remain > 0 {
@@ -33,7 +29,7 @@ func DesBase64Decrypt(crypted []byte) []byte {
 			result = append(result, 0)
 		}
 	}
-	origData, err := TripleDesDecrypt(result, []byte(key))
+	origData, err := TripleDesDecrypt(result, []byte(desKey))
 	if err != nil {
 		panic(err)
 	}