1

I have a C function:

AES_KEY* generate_aes128_key()  

which generates a AES_KEY*. struct AES_KEY is defined in openssl, and is allocated memory in the body of the function. I want to call this function in Java to get a AES_KEY, so how can I do it?

hexiecs
  • 312
  • 1
  • 12
  • 2
    It would almost certainly be easier (and quite possibly faster at run-time as well) to use [jasypt](http://www.jasypt.org/bouncy-castle.html). – Elliott Frisch Apr 27 '17 at 16:14
  • If you want to call native functions from Java then you're looking at using JNI or maybe JNA. A native pointer can *probably* be returned as a Java `long` (where "probably" accounts for the fact that native pointer sizes are implementation-dependant). That may not be quite what you want, however, because Java has no direct way of using the pointer-converted-to-`long`; you would need one or more additional native methods. – John Bollinger Apr 27 '17 at 16:21
  • 2
    The [list of standard security names](http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html) seems to suggest that this can be done with the java.security.\* and javax.crypto.\* classes. In particular, it says KeyGenerator must support AES 128-bit. – VGR Apr 27 '17 at 16:22
  • JNA will likely be the easiest approach. There's also SWIG, which can automatically generate Java bindings for C structs and C++ classes -- but that would cost you some time to set up. – Andy Thomas Apr 27 '17 at 16:35

0 Answers0