Background
My application has now reached a bottleneck where the slowest part of it is the AES encrypt and decrypt streams through which all data must pass. In order to overcome this I plan to implement this ciphering in native code via JNI and OpenSSL so that I may take advantage of things like AES-NI and direct memory access (my buffers are already direct, so I can already get a pointer to their memory region)
The Issue
It doesn't make sense to recreate the OpenSSL cipher with the key every time I need to cipher or decipher some data. If I were using Java I would simply store the Cipher instance as a field in the class, however since the cipher is a C "object", I can't do this.
The Question
How to tie a C "object" to a Java class instance, so that subsequent invocations can use the stored "object". I imagine this has something to do with storing the "object" pointer as a long into the Java class, and then dereferencing it, however I am not quite sure that this is entirely cross platform.
The Answer
Must be:
- Simplistic
- Fast
- Cross platform
Thanks for your time!