Explorar o código

feat:报告数据加密

Roc %!s(int64=2) %!d(string=hai) anos
pai
achega
cd49496c73
Modificáronse 3 ficheiros con 28 adicións e 2 borrados
  1. 1 1
      controllers/base_common.go
  2. 2 1
      utils/constants.go
  3. 25 0
      utils/des3.go

+ 1 - 1
controllers/base_common.go

@@ -56,7 +56,7 @@ func (c BaseCommon) Result() {
 	//content = []byte(utils.StringsToJSON(string(content)))
 	// 数据加密
 	if services.CheckEncryption(c.Ctx.Request.URL.Path) {
-		content = utils.DesBase64Encrypt(content)
+		content = utils.DesBase64EncryptV2(content, utils.REPORT_KEY)
 	}
 	c.Ctx.Output.Header("Content-Type", "application/json; charset=utf-8")
 	c.Ctx.Output.Body(content)

+ 2 - 1
utils/constants.go

@@ -94,7 +94,8 @@ var PermissionFiccClassifyArr = [...]string{"宏观经济", "化工产业", "黑
 var PermissionAllClassifyArr = [...]string{"宏观经济", "化工产业", "黑色产业", "有色产业", "权益"}
 
 const (
-	key = "zDeESsxsXuionhqSLZYHWcDJ" //全局加密KEY
+	key        = "zDeESsxsXuionhqSLZYHWcDJ" //全局加密KEY
+	REPORT_KEY = "Zdhuef3ajCLTpfGLn10cOJLJ" //报告加密Key
 )
 
 //缓存key

+ 25 - 0
utils/des3.go

@@ -185,3 +185,28 @@ func DecryptDESECB(d string, key []byte) ([]byte, error) {
 	out = PKCS5UnPadding(out)
 	return out, nil
 }
+
+//des3 + base64 encrypt
+func DesBase64EncryptV2(origData []byte, encryptKey string) []byte {
+	result, err := TripleDesEncrypt(origData, []byte(encryptKey))
+	if err != nil {
+		panic(err)
+	}
+	return []byte(base64.StdEncoding.EncodeToString(result))
+}
+
+func DesBase64DecryptV2(crypted []byte, encryptKey string) []byte {
+	result, _ := base64.StdEncoding.DecodeString(string(crypted))
+	remain := len(result) % 8
+	if remain > 0 {
+		mod := 8 - remain
+		for i := 0; i < mod; i++ {
+			result = append(result, 0)
+		}
+	}
+	origData, err := TripleDesDecrypt(result, []byte(encryptKey))
+	if err != nil {
+		panic(err)
+	}
+	return origData
+}