package main import ( "bytes" "crypto/aes" "crypto/cipher" "encoding/base64" "errors" "fmt" "time" "strings" "strconv" "net/http" "io/ioutil" ) const aesIvDefValue = "d846ea815f80c3a8" // change it const aesKeyDefValue = "a0530e3d4edf934c" // change it func main() { // Action 11:required parameter information dc := "CT2" uid := "ct2tmppl01" data := "{\"action\":11, \"ts\":"+strconv.Itoa(int(time.Now().UnixNano() / 1000000))+", \"uid\": \""+uid+"\", \"lang\":\"ch\", \"gType\":\"0\", \"mType\":\"8001\", \"windowMode\":2}" fmt.Println("data:", data) // encrypt data encbyte, _ := AesEncrypt([]byte(data), checkAesKey(aesKeyDefValue)) encryptString := strings.Replace(base64.StdEncoding.EncodeToString(encbyte), "+", "-", -1) fmt.Println("afterEncode:", encryptString) //decodeBytes, _ := base64.StdEncoding.DecodeString(encodeString) //decbyte, _ := AesDecrypt(decodeBytes, checkAesKey(aesKeyDefValue)) //fmt.Println("afterDecode:", string(decbyte[:])) // check environment Settings file apiURL := "https://api.jdb711.com/apiRequest.do" payload := strings.NewReader("dc=" + string(dc) + "&x=" + encryptString) // post req, _ := http.NewRequest("POST", apiURL, payload) req.Header.Add("content-type", "application/x-www-form-urlencoded") req.Header.Add("cache-control", "no-cache") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) //parse json and use the path url to login game fmt.Println(string(body)) } func checkAesKey(strKey string) []byte { keyLen := len(strKey) arrKey := []byte(strKey) if keyLen >= 32 { return arrKey[:32] } if keyLen >= 24 { return arrKey[:24] } if keyLen >= 16 { return arrKey[:16] } tmp := make([]byte, 16) for i := 0; i < 16; i++ { if i < keyLen { tmp[i] = arrKey[i] } else { tmp[i] = '0' } } return tmp } func AesEncrypt(plaintext []byte, key []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { fmt.Println("err=", err) return nil, errors.New("invalid decrypt key") } blockSize := block.BlockSize() plaintext = PKCS5Padding(plaintext, blockSize) iv := []byte(aesIvDefValue) blockMode := cipher.NewCBCEncrypter(block, iv) ciphertext := make([]byte, len(plaintext)) blockMode.CryptBlocks(ciphertext, plaintext) return ciphertext, nil } func AesDecrypt(ciphertext []byte, key []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { return nil, errors.New("invalid decrypt key") } blockSize := block.BlockSize() if len(ciphertext) < blockSize { return nil, errors.New("ciphertext too short") } iv := []byte(aesIvDefValue) if len(ciphertext)%blockSize != 0 { return nil, errors.New("ciphertext is not a multiple of the block size") } blockModel := cipher.NewCBCDecrypter(block, iv) plaintext := make([]byte, len(ciphertext)) blockModel.CryptBlocks(plaintext, ciphertext) plaintext = PKCS5UnPadding(plaintext) return plaintext, nil } func PKCS5Padding(src []byte, blockSize int) []byte { padding := blockSize - len(src)%blockSize padtext := bytes.Repeat([]byte{byte(padding)}, padding) return append(src, padtext...) } func PKCS5UnPadding(src []byte) []byte { length := len(src) unpadding := int(src[length-1]) return src[:(length - unpadding)] }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more