jd decode
This commit is contained in:
@@ -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...)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user