Commit 5adb637c by znw

密钥使用数组方式再加密

parent 8919c137
No preview for this file type
...@@ -4,7 +4,31 @@ ...@@ -4,7 +4,31 @@
#include <com_sobot_chat_core_SobotUtil.h> #include <com_sobot_chat_core_SobotUtil.h>
#include <md5.h> #include <md5.h>
const char *KEY = "sobot*&^%$#@!";
static const uint8_t *getKey() {
const int len = 13;
uint8_t *src = malloc(len + 1);
for (int i = 0; i < len; ++i) {
switch (i) {
case 0: src[i] = 's'; break;
case 1: src[i] = 'o'; break;
case 2: src[i] = 'b'; break;
case 3: src[i] = 'o'; break;
case 4: src[i] = 't'; break;
case 5: src[i] = '*'; break;
case 6: src[i] = '&'; break;
case 7: src[i] = '^'; break;
case 8: src[i] = '%'; break;
case 9: src[i] = '$'; break;
case 10: src[i] = '#'; break;
case 11: src[i] = '@'; break;
case 12: src[i] = '!'; break;
}
}
src[len] = '\0';
return src;
}
char *jstringToChar(JNIEnv *env, jstring jstr) { char *jstringToChar(JNIEnv *env, jstring jstr) {
char *rtn = NULL; char *rtn = NULL;
...@@ -28,8 +52,8 @@ JNIEXPORT jstring JNICALL Java_com_sobot_chat_core_SobotUtil_getKey ...@@ -28,8 +52,8 @@ JNIEXPORT jstring JNICALL Java_com_sobot_chat_core_SobotUtil_getKey
char *aa =jstringToChar(env,a); char *aa =jstringToChar(env,a);
char *cc =jstringToChar(env,c); char *cc =jstringToChar(env,c);
char *dd =jstringToChar(env,d); char *dd =jstringToChar(env,d);
char *result = (char *) malloc(strlen(aa) + strlen(dd)+ strlen(cc)+ strlen(KEY)); char *result = (char *) malloc(strlen(aa) + strlen(dd)+ strlen(cc)+ strlen(getKey()));
sprintf(result, "%s%s%s%s", aa,dd,cc,KEY); sprintf(result, "%s%s%s%s", aa,dd,cc,getKey());
MD5_CTX context = { 0 }; MD5_CTX context = { 0 };
MD5Init(&context); MD5Init(&context);
MD5Update(&context, result, strlen(result)); MD5Update(&context, result, strlen(result));
......
No preview for this file type
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment