MCPcopy Create free account
hub / github.com/ThePeppy/wechat-api-ipad / MmtlsEncryptData

Method MmtlsEncryptData

Mmtls/MmtlsEncryptData.go:11–148  ·  view source on GitHub ↗
(srcbindata []byte)

Source from the content-addressed store, hash-verified

9)
10
11func (httpclient *HttpClientModel) MmtlsEncryptData(srcbindata []byte) []byte {
12 httpclient.mmtlsClient.ClientSeq = 1
13 httpclient.mmtlsClient.ServerSeq = 1
14
15 var newsendbuffer = new(bytes.Buffer)
16 newsendbuffer.Write([]byte{0x01, 0x03, 0xf1, 0x01, 0x00, 0xa8})
17 newsendbuffer.Write([]byte(Cilent.RandSeq(32)))
18 time := time.Now().Unix()
19 binary.Write(newsendbuffer, binary.BigEndian, (int32)(time))
20 newsendbuffer.Write([]byte{0x00, 0x00, 0x00, 0x6f, 0x01, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x0f, 0x01})
21 newsendbuffer.Write(httpclient.mmtlsClient.Earlydatapart)
22 var newsendbuffer_content = new(bytes.Buffer)
23
24 binary.Write(newsendbuffer_content, binary.BigEndian, int32(newsendbuffer.Len()))
25 newsendbuffer_content.Write(newsendbuffer.Bytes())
26
27 //自定义newsendbufferhash
28 /*newsendbufferhash := sha256.New()
29 newsendbufferhash.Write(newsendbuffer_content.Bytes())
30 newsendbufferhashhash256 := newsendbufferhash.Sum(nil)*/
31
32 newsendbufferhashs := new(bytes.Buffer)
33 newsendbufferhashs.Write(newsendbuffer_content.Bytes())
34 newsendbufferhashhash256 := Getsha256(newsendbufferhashs.Bytes())
35
36 HkdfExpand_early_data := new(bytes.Buffer)
37 HkdfExpand_early_data.Write([]byte{0x65, 0x61, 0x72, 0x6c, 0x79, 0x20, 0x64, 0x61, 0x74, 0x61, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x65, 0x78, 0x70, 0x61, 0x6e, 0x73, 0x69, 0x6f, 0x6e})
38 HkdfExpand_early_data.Write(newsendbufferhashhash256)
39
40 hkdfexpand_shortencryptkey := Cilent.Hkdf_Expand(sha256.New, httpclient.mmtlsClient.Hkdfexpand_pskaccess_key, HkdfExpand_early_data.Bytes(), 28)
41 httpclient.mmtlsClient.Encrptshortmmtlskey = hkdfexpand_shortencryptkey[:16]
42 httpclient.mmtlsClient.Encrptshortmmtlsiv = hkdfexpand_shortencryptkey[16:28]
43
44 part1_data := new(bytes.Buffer)
45 part1_data.Write([]byte{0x19, 0xf1, 0x03})
46 binary.Write(part1_data, binary.BigEndian, int16(len(newsendbuffer_content.Bytes())))
47 part1_data.Write(newsendbuffer_content.Bytes())
48
49 //业务数据
50 part2_data_inputdata := new(bytes.Buffer)
51 part2_data_inputdata.Write([]byte{0x00, 0x00, 0x00, 0x10, 0x08, 0x00, 0x00, 0x00, 0x0b, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x12})
52 binary.Write(part2_data_inputdata, binary.BigEndian, int32(int(time)))
53
54 var xorkeyBuffer = bytes.NewReader(httpclient.mmtlsClient.Encrptshortmmtlsiv[8:12])
55 var xorkeyint uint32
56 binary.Read(xorkeyBuffer, binary.BigEndian, &xorkeyint)
57 xorkeyint = xorkeyint ^ uint32(httpclient.mmtlsClient.ClientSeq)
58 buf := new(bytes.Buffer)
59 binary.Write(buf, binary.BigEndian, xorkeyint)
60
61 var encryptmmtlsIv_seq = new(bytes.Buffer)
62 encryptmmtlsIv_seq.Write(httpclient.mmtlsClient.Encrptshortmmtlsiv[:8])
63 encryptmmtlsIv_seq.Write(buf.Bytes())
64
65 var aad_noop = new(bytes.Buffer)
66
67 binary.Write(aad_noop, binary.BigEndian, uint64(httpclient.mmtlsClient.ClientSeq))
68 aad_noop.Write([]byte{0x19, 0xf1, 0x03})

Callers 1

MMtlsPostMethod · 0.95

Calls 4

RandSeqFunction · 0.92
Hkdf_ExpandFunction · 0.92
NewAES_GCMEncrypterFunction · 0.92
Getsha256Function · 0.85

Tested by

no test coverage detected