I am writing a program which does security modules such as encryption, signing, etc… I had written library in C which does the above mentioned functionality. Now I am calling this C native functions from java by using jni.
The problem I am facing is I am unable to store the result(signed data or encrypted data)into the parameters passed by java. I want to store the result in parameters which I receive. please help me. Thanks alot in advance.
The following are the API that I use in java to call native functions
sign("sign",byte[] file,int filelen,byte[] output,int outputlen)
In native C call I will perform the sign on “file” which is a buffer consists of input file contents and I want to store it to the output. How can I do it can anyone help me I did not found any related information.
The following code allows your native code to directly access the contents of both primitive byte array inputs.
Depending on your performance considerations (i.e. if you want to ensure that you avoid copying the array data, or avoid concurrent access to the byte arrays), here is an example of using
GetPrimitiveArrayCritical.An NIO/direct buffer is only recommended if you need the buffer to be shared between native and Java code for longer than the duration of a single function call.