I want to convert unsigned char array to jbytearray and jbytearray to unsigned char array.
Here is what I want to do:
phase 1)
- unsigned char data1[] to jbytearray in jni.
- jbytearray to byte[] in java
- base 64 encoding byte[] to String and save in file.
phase 2)
- load String from saved file
- base 64 decoding String to byte[]
- byte[] to jbtearray
- jbytearray to unsinged char data2[] in jni
Here is my question:
unsigned char's range is 0 ~ 256
and byte(in java) -128 ~ 127
So, although there is overflow in convert between unsigned char and byte,
phase1) data1 and phase2) data2 are same correctly without any data loss?
In my opinion, I logged data1 and data2 with
__android_log_print("test", "data1 : %s", data1);
__android_log_print("test", "data2 : %s", data2);
and they looked like same.
but, I can't understand how it looks like same (even if overflow).
And assumed they are same, strangely something is not going well, in other logic.... (Data1 is encrytped with AES and I want to decrypt Data2 with is same as Data1)
ex.
unsigned char data1[32] = { 250, 100, 230, 120, .......};
task phase1) 2, 3 and phase2) 1,2,3
unsigned char data2[32] = { 250, 100, 230, 120, .......};
will be same?
if this way is wrong, what can I do?