#include #include #include #include #include #include #include #include #include #include #include void TestDecode() { auto cid = "YVQuIJXwW1k77yO0yLWWxvtwppyNOr4sQtDMv4f+7vIuBudxMOtZSttSJkc+gXsX"; MqttLog(MQTT_LOG_ERROR, "aes deocde: %s", cid); auto len = base64DecodeLength(cid, strlen(cid)); auto cbytes = new uint8_t[len]; auto retLen = base64Decode(cbytes, len, (uint8_t *)cid, strlen(cid)); auto need = aesDecryptLength(retLen); uint8_t *outBytes = new uint8_t[need]; auto outLen = aesDecrypt(cbytes, retLen, nullptr, outBytes); outBytes[outLen] = 0; MqttLog(MQTT_LOG_ERROR, "aes deocde result: %s", outBytes + 4); delete[] outBytes; delete[] cbytes; auto pas = "hN0AF2XX6+rD4vZEfafQo9Ant7O26OAqS9U9b8qUqg5qSDFfLwhaiQ=="; MqttLog(MQTT_LOG_ERROR, "des deocde: %s", pas); len = base64DecodeLength(pas, strlen(pas)); cbytes = new uint8_t[len]; retLen = base64Decode(cbytes, len, (uint8_t *)pas, strlen(pas)); need = desDecryptLength(retLen); outBytes = new uint8_t[need]; outLen = desDecrypt(cbytes, retLen, outBytes); outBytes[outLen] = 0; MqttLog(MQTT_LOG_ERROR, "des deocde result: %s", outBytes); delete[] outBytes; delete[] cbytes; } void TestAES() { int len = 0; uint8_t *tmp = new uint8_t[200]; uint8_t *tmp2 = new uint8_t[200]; uint8_t *out = new uint8_t[200]; for (size_t i = 0; i < 100; i++) { tmp[i] = i; } aesEncrypt((uint8_t *)"aabb", 4, nullptr, out); char *str = "LFwMv5a3x2bL0MaOz6ZGu3J6uQkYpD8mu///sYnHITtric8ejkHiI4kq86C+pIjyk3omkyxusUWngLiCzDTodGRl1OfRsXS8FMPivQ52LybxrnvuAi4UmuOCYoctqJ811AGmsHT1BhQYHfSRA5mpyQ=="; int n = base64Decode(tmp, 160, (uint8_t *)str, strlen(str)); base64Encode((char *)tmp2, 160, tmp, n); assert(strcmp(str, (char *)tmp2) == 0); n = aesDecrypt(tmp, n, nullptr, tmp2); tmp2[n] = 0; for (size_t i = 0; i < 50; i++) { auto need = aesEncryptLength(i); if (need <= 0) continue; auto dlen = aesEncrypt(tmp, i, nullptr, out); memset(&out[dlen], 0, 10); need = aesDecryptLength(dlen); dlen = aesDecrypt(out, dlen, nullptr, tmp2); assert(dlen == i); auto same = memcmp(tmp, tmp2, i); assert(same == 0); } } void TestDES() { int len = 0; uint8_t *tmp = new uint8_t[100]; uint8_t *tmp2 = new uint8_t[100]; uint8_t *out = new uint8_t[200]; for (size_t i = 0; i < 100; i++) { tmp[i] = i; } for (size_t i = 0; i < 50; i++) { auto need = desEncryptLength(i); if (need <= 0) continue; auto dlen = desEncrypt(tmp, i, out); memset(&out[dlen], 0, 10); need = desDecryptLength(dlen); dlen = desDecrypt(out, dlen, tmp2); assert(dlen == i); auto same = memcmp(tmp, tmp2, i); assert(same == 0); } } int main() { auto str = "AJBd+jzQToy8y2zl7199VsSD8hvVgJToyzDu07SCS06q"; ProtoParser parser; parser.setToken("", "aabb", "90d86418-9fd9-413c-a5e4-ea81d2897a13"); uint8_t bytes[] = {64, 53, 0, 1, 0, 0, 0, 235, 81, 247, 181, 34, 89, 204, 6, 118, 140, 79, 102, 119, 239, 109, 79, 129, 198, 31, 215, 153, 218, 57, 196, 215, 66, 4, 159, 68, 146, 1, 127, 53, 42, 39, 227, 147, 164, 123, 244, 1, 1, 13, 114, 144, 9, 121, 81}; std::vector data; data.insert(data.end(), bytes, bytes + sizeof(bytes)); parser.parse(data); auto s = parser.connectPack("test01#7548"); auto a = parser.getUserInfo("{\"request\":[{\"uid\":\"test01#7549\"}]}", ""); TestAES(); TestDES(); //TestDecode(); auto mqtt = mqttCreate("tcp://im.zljyhz.com:8993/"); if (mqtt == nullptr) { printf("create mqtt failed."); return -1; } mqttDestory(mqtt); return 0; }