解密完成
This commit is contained in:
@@ -85,7 +85,7 @@ func TestGetDistricts(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCoordinateFromAddress(t *testing.T) {
|
||||
lng, lat, districtCode := autonaviAPI.GetCoordinateFromAddress("广东广州市白云区棠景街道水边街棠下村东一街36号(可放北街的菜鸟驿站)", "广州")
|
||||
lng, lat, districtCode := autonaviAPI.GetCoordinateFromAddress("浙江杭州市萧山区萧山经济技术开发区建设四路龙湖天玺 16幢1单元3303室", "")
|
||||
t.Logf("lng:%f, lat:%f, districtCode:%d", lng, lat, districtCode)
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ func TestBatchWalkingDistance(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAA(t *testing.T) {
|
||||
result, err := autonaviAPI.GetCoordinateAreaInfo(113.325814, 23.133907)
|
||||
result, err := autonaviAPI.GetCoordinateAreaInfo(120.287109, 30.205960)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package jdshopapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
@@ -12,7 +11,7 @@ type CallBackResult struct {
|
||||
GetOrderResult
|
||||
}
|
||||
|
||||
func (a *API) GetCallbackMsg(request *http.Request) (call *CallBackResult, err error) {
|
||||
func (a *API) GetCallbackMsg(request *http.Request) (call *GetOrderResult, err error) {
|
||||
data, err := ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -22,7 +21,6 @@ func (a *API) GetCallbackMsg(request *http.Request) (call *CallBackResult, err e
|
||||
return nil, err
|
||||
}
|
||||
mapData := utils.URLValues2Map(values)
|
||||
fmt.Println(mapData)
|
||||
utils.Map2StructByJson(mapData, &call, false)
|
||||
return call, err
|
||||
}
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package jdshopapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
"unsafe"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"golang.org/x/text/encoding/simplifiedchinese"
|
||||
)
|
||||
|
||||
func TestCreateShopCategory(t *testing.T) {
|
||||
@@ -109,35 +106,25 @@ func TestTryGetCookie(t *testing.T) {
|
||||
func TestAAADS(t *testing.T) {
|
||||
str := "AASWvkdk5a60bjm3lFqaoCyzJprhJZvabCAbNtGu14Lu/ZBGNYf/MdPCEIcIN9oVbEw="
|
||||
data, _ := base64.StdEncoding.DecodeString(str)
|
||||
dataStr := hex.EncodeToString(data)
|
||||
fmt.Println("all:", dataStr) //96be4764e5aeb46e39b7945a9aa02cb3
|
||||
fmt.Println("key ID:", dataStr[4:36])
|
||||
fmt.Println("IV:", dataStr[36:68])
|
||||
fmt.Println("key main", dataStr[68:])
|
||||
// fmt.Println("all:", dataStr) //96be4764e5aeb46e39b7945a9aa02cb3
|
||||
// fmt.Println("key ID:", dataStr[4:36])
|
||||
// fmt.Println("IV:", dataStr[36:68])
|
||||
// fmt.Println("key main", dataStr[68:])
|
||||
data2, _ := base64.StdEncoding.DecodeString("XsGNdyDyDHnR79iKU6d5LTSJYaQyWAEssDoD7VM5Kks=")
|
||||
// str2 := []byte(dataStr[68:])
|
||||
// key := []byte(dataStr2)
|
||||
iv, _ := hex.DecodeString("269ae1259bda6c201b36d1aed782eefd")
|
||||
main, _ := hex.DecodeString("90463587ff31d3c210870837da156c4c")
|
||||
fmt.Println(iv)
|
||||
fmt.Println(data[18:34])
|
||||
decryptedData, err := Decrypt(main, data2, iv)
|
||||
b := bytes.NewBuffer(data)
|
||||
b.Next(18)
|
||||
iv := make([]byte, 16)
|
||||
b.Read(iv)
|
||||
main := make([]byte, len(data)-18-16)
|
||||
b.Read(main)
|
||||
// fmt.Println(data)
|
||||
// fmt.Println(main)
|
||||
// fmt.Println(iv)
|
||||
decryptedData, err := Decrypt(main, data2[:16], iv)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data3, _ := simplifiedchinese.GBK.NewDecoder().Bytes(decryptedData) //gbk 转 utf-8
|
||||
fmt.Println("data", string(data3))
|
||||
}
|
||||
|
||||
func TestSZXCXZ(t *testing.T) {
|
||||
//53cb68569fb790a8e17ae3b0c735991f
|
||||
// fmt.Println(len(data))
|
||||
}
|
||||
|
||||
func StringToBytes(s string) []byte {
|
||||
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
||||
bh := reflect.SliceHeader{sh.Data, sh.Len, 0}
|
||||
return *(*[]byte)(unsafe.Pointer(&bh))
|
||||
fmt.Println("data", string(decryptedData))
|
||||
}
|
||||
|
||||
func Decrypt(decryptBytes, key, iv []byte) ([]byte, error) {
|
||||
@@ -145,43 +132,13 @@ func Decrypt(decryptBytes, key, iv []byte) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(block.BlockSize())
|
||||
blockMode := cipher.NewCBCDecrypter(block, iv)
|
||||
decrypted := make([]byte, len(decryptBytes))
|
||||
blockMode.CryptBlocks(decrypted, decryptBytes)
|
||||
fmt.Println(decrypted)
|
||||
decrypted = PKCS5UnPadding(decrypted)
|
||||
return decrypted, nil
|
||||
blockMode.CryptBlocks(decryptBytes, decryptBytes)
|
||||
return PKCS5UnPadding(decryptBytes), nil
|
||||
}
|
||||
|
||||
func PKCS5UnPadding(decrypted []byte) []byte {
|
||||
length := len(decrypted)
|
||||
fmt.Println(length)
|
||||
unPadding := int(decrypted[length-1])
|
||||
fmt.Println(unPadding)
|
||||
return decrypted[:(length - unPadding)]
|
||||
}
|
||||
|
||||
func CBCDecript(src, key, iv []byte) (dst []byte, err error) {
|
||||
var (
|
||||
block cipher.Block
|
||||
blockMode cipher.BlockMode
|
||||
)
|
||||
|
||||
if len(iv) != aes.BlockSize {
|
||||
return nil, fmt.Errorf("iv")
|
||||
}
|
||||
if len(key) != 32 {
|
||||
return nil, fmt.Errorf("key")
|
||||
}
|
||||
|
||||
if block, err = aes.NewCipher(key); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blockMode = cipher.NewCBCDecrypter(block, iv)
|
||||
dst = make([]byte, len(src))
|
||||
blockMode.CryptBlocks(dst, src)
|
||||
dst = PKCS5UnPadding(dst)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user