|
@@ -13,66 +13,6 @@
|
|
|
#include "include/logger.h"
|
|
|
#include "aes/aes_utils.h"
|
|
|
|
|
|
-static void GetAesKey(JNIEnv *env, jobject thiz) {
|
|
|
- uint8_t *aes_key = AesUtils::GetKey();
|
|
|
- uint8_t *iv = AesUtils::GetIv(aes_key);
|
|
|
- LOGD("%s", aes_key);
|
|
|
- LOGD("%s", iv);
|
|
|
- LOGD("------ invoke free() ------ ");
|
|
|
- free(aes_key);
|
|
|
- free(iv);
|
|
|
-// free((void *) aes_key);
|
|
|
-// free((void *) iv);
|
|
|
- aes_key = nullptr;
|
|
|
- iv = nullptr;
|
|
|
- LOGD("%s", aes_key);
|
|
|
- LOGD("%s", iv);
|
|
|
-}
|
|
|
-
|
|
|
-//static jstring AesEncrypt(JNIEnv *env, jobject thiz, jstring src) {
|
|
|
-// const char *src_ = env->GetStringUTFChars(src, JNI_FALSE);
|
|
|
-// char *raw = AesUtils::Encrypt(src_);
|
|
|
-// LOGD("%s", raw);
|
|
|
-//
|
|
|
-// env->ReleaseStringUTFChars(src, src_);
|
|
|
-//
|
|
|
-// jstring result = ToolKit::GetJString(env, raw);
|
|
|
-// free(raw);
|
|
|
-//
|
|
|
-// return result;
|
|
|
-//}
|
|
|
-
|
|
|
-static jstring AesDecrypt(JNIEnv *env, jobject thiz, jstring raw, jstring key) {
|
|
|
- const char *raw_ = env->GetStringUTFChars(raw, JNI_FALSE);
|
|
|
- const auto *key_ = reinterpret_cast<const uint8_t *>(env->GetStringUTFChars(key, JNI_FALSE));
|
|
|
- char *src = AesUtils::Decrypt(raw_, key_);
|
|
|
- env->ReleaseStringUTFChars(raw, raw_);
|
|
|
- jstring result = ToolKit::GetJString(env, src);
|
|
|
- free(src);
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-//static jstring RsaEncrypt(JNIEnv *env, jobject thiz, jstring src) {
|
|
|
-// const char *src_ = env->GetStringUTFChars(src, JNI_FALSE);
|
|
|
-// std::string key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCAVatPhPaZtxBkLBZDnOLf7no6VfnjBRMXhpOnWmkkDX4zurB/OKisYDFnR0UUVnKn717+absfLlDk9HZWBcTMznsUju9fuXlu3Elr8HeI3en7E0KIQzxkY1GT1+qtZ+tCjWuyMmUw4vWpO8/MRU3f6nc4io3w+7N+dP24BIo0ZwIDAQAB";
|
|
|
-// std::string raw = RsaUtils::EncryptByPublicKey(key, src_);
|
|
|
-//// LOGD("base64 raw : %s", raw.c_str());
|
|
|
-// env->ReleaseStringUTFChars(src, src_);
|
|
|
-// jstring result = ToolKit::GetJString(env, raw.c_str());
|
|
|
-// return result;
|
|
|
-//}
|
|
|
-//
|
|
|
-//static jstring RsaDecrypt(JNIEnv *env, jobject thiz, jstring raw) {
|
|
|
-// const char *raw_ = env->GetStringUTFChars(raw, JNI_FALSE);
|
|
|
-//// std::string key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCAVatPhPaZtxBkLBZDnOLf7no6VfnjBRMXhpOnWmkkDX4zurB/OKisYDFnR0UUVnKn717+absfLlDk9HZWBcTMznsUju9fuXlu3Elr8HeI3en7E0KIQzxkY1GT1+qtZ+tCjWuyMmUw4vWpO8/MRU3f6nc4io3w+7N+dP24BIo0ZwIDAQAB";
|
|
|
-// std::string key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbROlODv7iVaFhRAomQ9kSoV+whoebwVUDWUd968V8jbLQg0bAh6ad22O1bo33f4zNmIuDzdQMGOVgRyuvKsS9GyE+gh4XPDpSUmi/bZTl0wr8Y/yTi8eW+sXxn6Ao4oo4bg+qPewUxjTS2u4Pe1Zl3IC48HFALTAo0PSSXS5b7wIDAQAB";
|
|
|
-// std::string src = RsaUtils::DecryptByPublicKey2(env, key, raw_);
|
|
|
-// env->ReleaseStringUTFChars(raw, raw_);
|
|
|
-// jstring result = ToolKit::GetJString(env, src.c_str());
|
|
|
-// return result;
|
|
|
-//}
|
|
|
-
|
|
|
static void InitSdkDrive(JNIEnv *env, jobject thiz, jobject context) {
|
|
|
CommMap::GetInstance()->Init(env, context);
|
|
|
Logger::is_debug = ParamsKit::GetDebugModel(env, context);
|
|
@@ -101,18 +41,25 @@ static jstring GetParam(JNIEnv *env, jobject thiz, jstring key) {
|
|
|
static jstring InvokeJob(JNIEnv *env, jobject thiz, jobject context, jstring key, jstring data) {
|
|
|
const char *key_ = env->GetStringUTFChars(key, JNI_FALSE);
|
|
|
const char *data_ = env->GetStringUTFChars(data, JNI_FALSE);
|
|
|
-// Json::Value root = ToolKit::ToJsonObject(data_);
|
|
|
-// if (root.)
|
|
|
-// LOGD("aaaaa , %s", data_);
|
|
|
-// LOGD("json str %s", root.asCString());
|
|
|
-// std::string raw = ToolKit::ToJsonString(root);
|
|
|
-// LOGD("aes key : %s", raw);
|
|
|
- char *enc = AesUtils::Encrypt(data_, reinterpret_cast<const uint8_t *>(key_));
|
|
|
- jstring result = ToolKit::GetJString(env, enc);
|
|
|
+
|
|
|
+ //添加公共参数
|
|
|
+ Json::Value root = ToolKit::ToJsonObject(data_);
|
|
|
+ root["common"] = CommMap::GetInstance()->comm_params;
|
|
|
+
|
|
|
+ //生成aes key
|
|
|
+// char *raw_key = AesUtils::GetRawKey();
|
|
|
+// std::string md5_key = md5(raw_key);
|
|
|
+// auto *key64= static_cast<char *>(malloc(65));
|
|
|
+// memset(key64,0,64);
|
|
|
+// sprintf(key64,"%s%s",md5_key,reverse(md5_key.begin(),md5_key.end()))
|
|
|
+// std::string aes_key=md5()
|
|
|
+ LOGD("test : %s", ToolKit::StrReverse(key_));
|
|
|
+ char *p = AesUtils::Encrypt(ToolKit::ToJsonString(root).c_str(), reinterpret_cast<const uint8_t *>(key_));
|
|
|
+ jstring result = ToolKit::GetJString(env, p);
|
|
|
env->ReleaseStringUTFChars(key, key_);
|
|
|
env->ReleaseStringUTFChars(data, data_);
|
|
|
// delete (raw);
|
|
|
- free(enc);
|
|
|
+ free(p);
|
|
|
return result;
|
|
|
|
|
|
// std::string enc = RequestKit::EncryptRequest2(env, context, data);
|
|
@@ -162,6 +109,12 @@ static jstring ParseJob(JNIEnv *env, jobject thiz, jobject context, jstring key,
|
|
|
// return env->NewStringUTF("");
|
|
|
}
|
|
|
|
|
|
+static jstring Test(JNIEnv *env, jobject thiz) {
|
|
|
+ char *key = AesUtils::GetRawKey();
|
|
|
+ jstring result = ToolKit::GetJString(env, key);
|
|
|
+ free(key);
|
|
|
+ return result;
|
|
|
+}
|
|
|
|
|
|
static JNINativeMethod gMethod[] = {
|
|
|
{"initSdkDrive", "(Landroid/content/Context;)V", (void *) InitSdkDrive},
|
|
@@ -169,12 +122,7 @@ static JNINativeMethod gMethod[] = {
|
|
|
{"getParam", "(Ljava/lang/String;)Ljava/lang/String;", (void *) GetParam},
|
|
|
{"invokeJob", "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void *) InvokeJob},
|
|
|
{"parseJob", "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void *) ParseJob},
|
|
|
-
|
|
|
-// {"getAesKey", "()V", (void *) GetAesKey},
|
|
|
-// {"aesEncrypt", "(Ljava/lang/String;)Ljava/lang/String;", (void *) AesEncrypt},
|
|
|
-// {"aesDecrypt", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void *) AesDecrypt},
|
|
|
-// {"rsaEncrypt", "(Ljava/lang/String;)Ljava/lang/String;", (void *) RsaEncrypt},
|
|
|
-// {"rsaDecrypt", "(Ljava/lang/String;)Ljava/lang/String;", (void *) RsaDecrypt}
|
|
|
+ {"test", "()Ljava/lang/String;", (void *) Test},
|
|
|
};
|
|
|
|
|
|
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|