我不知道为什么下面的代码会返回“Hello native!Th”而不是“Hello native!这是jni加载!\ n”,有人可能会提示它吗?AES_encrypt/AES_decrypt只返回部分消息
#include "helloJNI.h"
#include "openssl/aes.h"
#define LEN 1024
jstring jni_text(JNIEnv *env, jclass clz)
{
AES_KEY aesKey;
int result;
const char origin[] = "Hello native! This is from jni load!\n";
char out[LEN];
char outout[LEN];
memset(out, '\0', sizeof(out));
memset(outout, '\0', sizeof(outout));
result = AES_set_encrypt_key((const unsigned char *)"abc123", 256, &aesKey);
LOGE("encypt key result %d\n", result); /* is 0 */
AES_encrypt((const unsigned char *)origin, (unsigned char *)out, &aesKey);
LOGE("after encrypt, chars is %s\n", out);
result = AES_set_decrypt_key((const unsigned char *)"abc123", 256, &aesKey);
LOGE("decrypt key result %d\n", result); /* is 0 */
AES_decrypt(out, outout, &aesKey);
LOGE("after decrypt, chars is %s\n", outout);
return (*env)->NewStringUTF(env, outout); /* return "Hello native! Th" */
}
你为什么要为此编写JNI?它可以直接用Java完成。 – EJP