jd decode

This commit is contained in:
richboo111
2022-10-26 14:33:29 +08:00
parent bfe333c010
commit c37c869c33
6 changed files with 100 additions and 34 deletions

View File

@@ -1,6 +1,8 @@
package utils
import (
"crypto/aes"
"encoding/base64"
"fmt"
"strconv"
"strings"
@@ -27,6 +29,35 @@ func NewErrorCode(errMsg, code string, level ...int) *ErrorWithCode {
return retVal
}
func DecryptDESECB(d, key []byte) string {
data, err := base64.StdEncoding.DecodeString(string(d))
if err != nil {
return ""
}
block, err := aes.NewCipher(key)
if err != nil {
return ""
}
bs := block.BlockSize()
if len(data)%bs != 0 {
return ""
}
out := make([]byte, len(data))
dst := out
for len(data) > 0 {
block.Decrypt(dst, data[:bs])
data = data[bs:]
dst = dst[bs:]
}
out = PKCS5UnPadding(out)
return string(out)
}
func PKCS5UnPadding(origData []byte) []byte {
length := len(origData)
unpadding := int(origData[length-1])
return origData[:(length - unpadding)]
}
func NewErrorIntCode(errMsg string, code int, level ...int) *ErrorWithCode {
return NewErrorCode(errMsg, Int2Str(code), level...)
}

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"crypto/aes"
"crypto/cipher"
"fmt"
)
func AESCBCEncpryt(data, aesKey, iv []byte) (encryptedData []byte, err error) {
@@ -23,9 +24,11 @@ func AESCBCDecpryt(encryptedData, aesKey, iv []byte) (decryptedData []byte, err
if err != nil {
return nil, err
}
fmt.Println(c.BlockSize(), len(encryptedData))
cfbdec := cipher.NewCBCDecrypter(c, iv[:c.BlockSize()])
decryptedData = make([]byte, len(encryptedData))
cfbdec.CryptBlocks(decryptedData, encryptedData)
decryptedData = PKCSUnPadding(decryptedData)
return decryptedData, nil
}