|
@@ -2,13 +2,14 @@ package utils
|
|
|
|
|
|
import (
|
|
|
"bufio"
|
|
|
+ "crypto/cipher"
|
|
|
+ "crypto/des"
|
|
|
"crypto/md5"
|
|
|
"crypto/sha1"
|
|
|
"encoding/base64"
|
|
|
"encoding/hex"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
- "github.com/shopspring/decimal"
|
|
|
"image"
|
|
|
"image/png"
|
|
|
"io"
|
|
@@ -23,6 +24,8 @@ import (
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
+
|
|
|
+ "github.com/shopspring/decimal"
|
|
|
)
|
|
|
|
|
|
// 随机数种子
|
|
@@ -1164,3 +1167,41 @@ func DateConvMysqlConvMongo(dateCon string) string {
|
|
|
}
|
|
|
return cond
|
|
|
}
|
|
|
+
|
|
|
+func DesBase64Decrypt(crypted []byte, desKey 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(desKey))
|
|
|
+ if err != nil {
|
|
|
+ panic(any(err))
|
|
|
+ }
|
|
|
+ return origData
|
|
|
+}
|
|
|
+
|
|
|
+// // 3DES解密
|
|
|
+func TripleDesDecrypt(crypted, key []byte) ([]byte, error) {
|
|
|
+ block, err := des.NewTripleDESCipher(key)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ blockMode := cipher.NewCBCDecrypter(block, key[:8])
|
|
|
+ origData := make([]byte, len(crypted))
|
|
|
+ // origData := crypted
|
|
|
+ blockMode.CryptBlocks(origData, crypted)
|
|
|
+ origData = PKCS5UnPadding(origData)
|
|
|
+ // origData = ZeroUnPadding(origData)
|
|
|
+ return origData, nil
|
|
|
+}
|
|
|
+
|
|
|
+func PKCS5UnPadding(origData []byte) []byte {
|
|
|
+ length := len(origData)
|
|
|
+ // 去掉最后一个字节 unpadding 次
|
|
|
+ unpadding := int(origData[length-1])
|
|
|
+ return origData[:(length - unpadding)]
|
|
|
+}
|