diff --git a/ccc-jni/src/main/java/io/malloc/ccc/MainActivity2.java b/ccc-jni/src/main/java/io/malloc/ccc/MainActivity2.java new file mode 100644 index 0000000..5892c54 --- /dev/null +++ b/ccc-jni/src/main/java/io/malloc/ccc/MainActivity2.java @@ -0,0 +1,72 @@ +/* + + */ +package io.malloc.ccc; + +import android.support.v4.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import com.wolfssl.wolfcrypt.Aes; +import com.wolfssl.wolfcrypt.WolfCryptException; + +import io.malloc.ccc.Util; +/* + * Simple Java UI to trigger jni function. It is exactly same as Java code + * in hello-jni. + */ +public class MainActivity extends AppCompatActivity { + + private static final byte[] KEY = Util.h2b("00112233445566778899AABBCCDDEEFF"); + private static final byte[] IV = Util.h2b("000102030405060708090A0B0C0D0E0F"); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + + // Aes aes = new Aes(); + // TextView tv = new TextView(this); + // tv.setText( stringFromJNI() ); + // setContentView(tv); + } +// public native String stringFromJNI(); + static { + + System.loadLibrary("wolfssl-jni"); + } + + @Override + protected void onStart() { + super.onStart(); +// final Button button = (Button) findViewById(R.id.AESbutton); +// button.setOnClickListener(new View.OnClickListener() { +// public void onClick(View v) { +// checkSetKeyParams(); +// } +// }); + } + + public void checkSetKeyParams() { + /* iv is optional, should not raise. */ + Aes aes = new Aes(KEY, null, Aes.ENCRYPT_MODE); + + try { + aes.setKey(null, IV, Aes.ENCRYPT_MODE); + } catch (WolfCryptException e) { + System.out.println("ERROR: WolfCrypt: J3G: "+e.getMessage()); + } + + aes.setKey(KEY, IV, Aes.ENCRYPT_MODE); + aes.releaseNativeStruct(); + + try { + aes.setKey(KEY, IV, Aes.ENCRYPT_MODE); + } catch (WolfCryptException e) { + System.out.println("ERROR: WolfCrypt: J3G: "+e.getMessage()); + } + } +} + diff --git a/ccc-jni/src/main/java/io/malloc/ccc/Util.java b/ccc-jni/src/main/java/io/malloc/ccc/Util.java new file mode 100644 index 0000000..f5234f7 --- /dev/null +++ b/ccc-jni/src/main/java/io/malloc/ccc/Util.java @@ -0,0 +1,32 @@ +/* + + */ +package io.malloc.ccc; + +class Util { + public static byte[] h2b(String s) { + int len = s.length(); + byte[] data = new byte[len / 2]; + + for (int i = 0; i < len; i += 2) { + data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character + .digit(s.charAt(i + 1), 16)); + } + + return data; + } + + final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); + + public static String b2h(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + + for (int j = 0; j < bytes.length; j++) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + + return new String(hexChars); + } +} diff --git a/nc-libs/wolfssl-jni.aar b/nc-libs/wolfssl-jni.aar new file mode 100644 index 0000000..8b60775 Binary files /dev/null and b/nc-libs/wolfssl-jni.aar differ