Returning unsinged char* from JNI C++ to Java

Put problems with the Android NDK in this forum.

Returning unsinged char* from JNI C++ to Java

Postby vinayjulme » Fri May 13, 2011 10:26 am

In my code i pass a string and then hash it using HMAC SHA1 algo and then try to return it to Java. But it is not returning.

The code is as follows:

return env->NewStringUTF((const char*)digest);
On the statement VM Aborts.

where digest is and unsigned char which has a hashed characters. I logged digest variable and it showed some ascii values. Probably after hashing it mush have got few characters like that.

My Function is as follows:
Code: Select all
typedef unsigned char BYTE ;
unsigned char *test = (unsigned char *)"Hi There" ;
BYTE Key[20] ;
BYTE digest[20] ;
jstring Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz )
   memset(Key, 0x0b, 20) ;

        ////////Next 2 lines are for Hashing the given text
   HMAC_SHA1.HMAC_SHA1(test, strlen((const char *)test), Key, sizeof(Key), digest) ;
   __android_log_write(ANDROID_LOG_ERROR,"Hello-Sample",(const char *)digest);
   jstring temp = env->NewStringUTF((const char*)digest);
    return temp;

Can someone please tell me what can be the problem and how to rectify it?
Once Poster
Once Poster
Posts: 1
Joined: Mon Nov 29, 2010 6:24 pm


Return to NDK Problems

Who is online

Users browsing this forum: Google Feedfetcher and 3 guests