我想多次调用MD5函数并使用强制代码返回结果。
char *finalenc= (char*)malloc(32);
finalenc = "";
for (int i = 0; i < md5repeatTime; ++i) {
if (i == 0)
finalenc = md5(env, chtime, 0);
else {
finalenc = md5(env, finalenc, 0);
}
}
__android_log_write(ANDROID_LOG_ERROR, "releasetimefortest", finalenc);
我有两个问题:
libc:致命信号6(SIGABRT)位于0x000006df
修改:
char *md5(JNIEnv *env, char *cstr, int mode) {
MD5_CTX context = {0};
MD5Init(&context);
MD5Update(&context, (unsigned char *) cstr, strlen(cstr));
unsigned char dest[16] = {0};
MD5Final(dest, &context);
char mdString[33];
int i;
for (i = 0; i < 16; i++) {
sprintf(&mdString[i*2], "%02x", (unsigned int)dest[i]);
}
return mdString;
}
答案 0 :(得分:0)
最后我找到了解决方案: md5功能:
char *md5(JNIEnv *env, char *cstr,char mdString[65]) {
MD5_CTX context = {0};
MD5Init(&context);
MD5Update(&context, (unsigned char *) cstr, strlen(cstr));
unsigned char dest[16] = {0};
MD5Final(dest, &context);
// (*env)->ReleaseStringUTFChars(env, data, cstr);
// char mdString[33];
int i;
for (i = 0; i < 16; i++) {
sprintf(&mdString[i*2], "%02x", (unsigned int)dest[i]);
}
return mdString;
}
以及调用该功能
char mdString[65]={0};
if (md5enable == 1) {
for (int i = 0; i < md5repeatTime; ++i) {
if (i == 0) {
md5(env, chtime, mdString);
}
else {
md5(env, mdString,mdString);
}
}
}