diff --git a/FigureOutJNICrash.md b/FigureOutJNICrash.md index 7a526fb..a7be0b3 100644 --- a/FigureOutJNICrash.md +++ b/FigureOutJNICrash.md @@ -2,13 +2,16 @@ How to locate where native crash at? ------------ 1.ensure you ndk is set into environment. -2.run **ndk-stack** to analyze logcat which code crash printed. +2.run **ndk-stack** to analyze logcat and **symbol file** to find where crash printed. ``` -adb logcat | ndk-stack -sym ../obj/local/armeabi-v7a/ -//or -adb logcat | ndk-stack -sym ../obj/local/x86/ +//or you use gradlew build command: +adb logcat | ndk-stack -sym ./aesjni/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/ +//or you using ndk-build command: +adb logcat | ndk-stack -sym ./aesjni/src/main/obj/local/x86/ ``` > **../obj/local/x86/** and **../obj/local/armeabi-v7a/** is symbol file directory. + + ### Example: I got crash logs: @@ -61,7 +64,8 @@ Stack frame #05 pc 0000113d /data/local/tmp/test: Routine main at /Users/bruce/ ``` -My conclusion: `/Users/******/git/AESJniEncrypt/aesjni/src/main/jni/main_unit_test.c:146` is where the executable file crash at. +`/Users/******/git/AESJniEncrypt/aesjni/src/main/jni/main_unit_test.c:146` show me that +executable file crash at `line 146 from main_unit_test.c`. ## Remind *ndk-stack* of NDK-R13 **only supports** symbol file of armeabi-v7a. diff --git a/README.md b/README.md index 575b27c..36cb136 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ # Reach high security in Android -- [x] Add AES algorithms to native code +- [x] ~~AES algorithms~~,it is low-performance,so it has been deprecated. +- [x] use chacha20 instead of AES. TLS1.3 used chacha20 on mobile device too,it is high-performance for arm. - [x] Hide native function in JniOnload - [x] Use signature verification to avoid being packaged again (It is prevents that hacker call your jni method directly.) - [x] ~~key exists in the symbol table, and hides the character table~~ This scheme has been deprecated, [discard reason issues5](https://github.com/weizongwei5/AESJniEncrypt/issues/5), please see the next @@ -16,9 +17,10 @@ - [x] Masking the simulator when the code is run: The code comes from my another repository [Check_Emulator_In_NDK](https://github.com/Scavenges/Check_Emulator_In_NDK) - [ ] TODO: Prevent SO file being code inject -``` -Char * key = "NMTIzNDU2Nzg5MGFiY2RlZg"; / / Here is the key is processed and stored here, in fact the real key is: "1234567890abcdef" -``` + +## Before you clone +install GIT-LFS: https://git-lfs.github.com/ + ## Build & Integration a. Set ndk.dir in local.properties Requires that the ndk version must be 11-13b. High version ndk has not been tested, and may doesn't compiled. @@ -90,3 +92,8 @@ In case you would like to add information to this repository or suggest some ide [https://github.com/zxp0505](https://github.com/zxp0505) [https://github.com/baoyongzhang](https://github.com/baoyongzhang) + + +## Legal +If you live in China, you should take care about [checking apk signature](https://github.com/BruceWind/AESJniEncrypt/blob/master/aesjni/src/main/cpp/check_emulator.c#L43). +I have called PackageManger ,it might be thought to read installed apps list,look at [工信部整治八项违规](http://www.miit.gov.cn/n1146295/n7281315/c7507241/part/7507297.docx). diff --git a/README_zh.md b/README_zh.md index cf31bc8..7e63063 100644 --- a/README_zh.md +++ b/README_zh.md @@ -3,8 +3,8 @@ [中文](https://github.com/BruceWind/AESJniEncrypt/blob/master/README_zh.md) # 追求极致的代码安全性保障 -- [x] ~~ndk实现AES加密~~,性能不佳,已废弃此方式,TLS1.3 -- [ ] 使用chacha20加密,TLS1.3在移动端都用了chacha20了 +- [x] ~~ndk实现AES加密~~,性能不佳,已废弃此方式 +- [ ] 使用chacha20加密,TLS1.3在移动端都用了chacha20了,性能更好 - [x] 使用JniOnload 隐藏c函数 - [x] 使用签名校验避免被再次打包(这是绕过破解加密算法直接调用你的jni函数) - [x] ~~key存在符号表中,同时隐藏字符表~~ 该方案已经废弃,[废弃原因issues5](https://github.com/weizongwei5/AESJniEncrypt/issues/5),请看下一条 @@ -15,10 +15,6 @@ - [x] 代码run的时候屏蔽模拟器 :代码来自我的另外一个仓库[Check_Emulator_In_NDK](https://github.com/Scavenges/Check_Emulator_In_NDK) - [ ] TODO:防止so代码被code inject -``` -char * key = "NMTIzNDU2Nzg5MGFiY2RlZg";//这里是key被做过处理存储在这里的,实际上真实的key是:"1234567890abcdef" -``` - ## 克隆代码准备 先安装GIT-LFS: https://git-lfs.github.com/ @@ -95,4 +91,7 @@ Native代码混淆器:[obfuscation-o-llvm-ndk](https://fuzion24.github.io/andr 有问题及时提:[new issues](https://github.com/weizongwei5/AESJniEncrypt/issues/new) - +## 合规 +如果你生活在中国,请注意[工信部整治八项违规](http://www.miit.gov.cn/n1146295/n7281315/c7507241/part/7507297.docx). +我调用了PackageManger[检查签名](https://github.com/BruceWind/AESJniEncrypt/blob/master/aesjni/src/main/cpp/check_emulator.c#L43),我只是**读取当前安装的app**, 这可能被认为**收集了安装列表**。从规定上来讲并不违规,只是读取了,并没**收集**,收集是违规的,读取是合规的。 +只是目前有可能被误认为**收集**。 diff --git a/aesjni/build.gradle b/aesjni/build.gradle index 739c565..4bc13e6 100644 --- a/aesjni/build.gradle +++ b/aesjni/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.library' android { compileSdkVersion 25 + buildToolsVersion "25.0.3" //ndkPath "/Users/bruce/Library/Android/sdk/ndk/16.1.4479499" // ndkVersion '16.1.4479499' defaultConfig { @@ -18,11 +19,20 @@ android { } ndk { + moduleName = "JNIEncrypt" // Specifies the ABI configurations of your native // libraries Gradle should build and package with your APK. - abiFilters 'x86' + abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86' } +// sourceSets { +// main { +// // The libs directory contains prebuilt libraries that are used by the +// // app's library defined in CMakeLists.txt via an IMPORTED target. +// jniLibs.srcDirs = ['libs'] +// } +// } + } @@ -59,5 +69,10 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) implementation 'com.android.support:appcompat-v7:25.0.1' - testImplementation 'junit:junit:4.12' + // Required for local unit tests (JUnit 4 framework) + implementation 'junit:junit:4.12' + + // Required for instrumented tests + androidTestCompile 'com.android.support:support-annotations:24.0.0' + androidTestCompile 'com.android.support.test:runner:0.5' } diff --git a/aesjni/src/androidTest/java/com/androidyuan/aesjni/JNITest.java b/aesjni/src/androidTest/java/com/androidyuan/aesjni/JNITest.java index 1fdc042..0b25df8 100644 --- a/aesjni/src/androidTest/java/com/androidyuan/aesjni/JNITest.java +++ b/aesjni/src/androidTest/java/com/androidyuan/aesjni/JNITest.java @@ -15,15 +15,19 @@ @RunWith(AndroidJUnit4.class) public class JNITest { - private final String plain = "123abcABC*%!~#+_/中文测试"; - private final String encodeStr = "1cad994119e4f3038fe29e34a4a12ce8a4b28f06db7682ab9d4f775c0e25659b01da27db09368eb3778ccea063"; + private static final String PLAIN = "123abcABC*%!~#+_/中文测试"; + private static final String ENCODE_STR = "1cad994119e4f3038fe29e34a4a12ce8a4b28f06db7682ab9d4f775c0e25659b01da27db09368eb3778ccea063"; @Test public void useAppContext() throws Exception { - //plain:123abcABC&*(@#@#@)+_/中文测试 - final String code = AESEncrypt.encode(this, plain); - assertEquals(code,encodeStr); - final String decode = AESEncrypt.decode(this, encodeStr); - assertEquals(plain,decode); + // Context of the app under test. +// Context appContext = InstrumentationRegistry.getTargetContext(); +// assertEquals(EncryptEntry.checkSignature(appContext),1); + + //plain:"123abcABC&*(@#@#@)+_/中文测试" + final String code = EncryptEntry.encode(this, PLAIN); + assertEquals(code,ENCODE_STR); + final String decode = EncryptEntry.decode(this, ENCODE_STR); + assertEquals(PLAIN,decode); } } diff --git a/aesjni/src/main/cpp/JNIEncrypt.c b/aesjni/src/main/cpp/JNIEncrypt.c index 51b13e0..5620439 100644 --- a/aesjni/src/main/cpp/JNIEncrypt.c +++ b/aesjni/src/main/cpp/JNIEncrypt.c @@ -14,7 +14,7 @@ // 获取数组的大小 # define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) // 指定要注册的类,对应完整的java类名 -#define JNIREG_CLASS "com/androidyuan/aesjni/AESEncrypt" +#define JNIREG_CLASS "com/androidyuan/aesjni/EncryptEntry" const char *UNSIGNATURE = "UNSIGNATURE"; diff --git a/aesjni/src/main/cpp/checksignature.c b/aesjni/src/main/cpp/checksignature.c index d172c26..f41a147 100644 --- a/aesjni/src/main/cpp/checksignature.c +++ b/aesjni/src/main/cpp/checksignature.c @@ -54,7 +54,7 @@ jint check_signature(JNIEnv *env, jobject thiz, jobject context) { jint hashCode = (*env)->CallIntMethod(env, signature, methodID_hashcode); //LOGE("hashcode: %d\n", hashCode); - if (strcmp(package_name, app_packageName) != 0) { + if (strcmp(package_name, app_pkg_name) != 0) { return -1; } if (hashCode != app_signature_hash_code) { diff --git a/aesjni/src/main/cpp/checksignature.h b/aesjni/src/main/cpp/checksignature.h index fd24b78..96d11ea 100644 --- a/aesjni/src/main/cpp/checksignature.h +++ b/aesjni/src/main/cpp/checksignature.h @@ -10,7 +10,7 @@ //合法的APP包名 -static const char *app_packageName = "com.androidyuan.aesjniencrypt"; +static const char *app_pkg_name = "com.androidyuan.aesjniencrypt"; //this value is generated by com.androidyuan.aesjni.SignatureTool.java. //-625644214 is hash of keystore file. diff --git a/aesjni/src/main/java/com/androidyuan/aesjni/AESEncrypt.java b/aesjni/src/main/java/com/androidyuan/aesjni/EncryptEntry.java similarity index 82% rename from aesjni/src/main/java/com/androidyuan/aesjni/AESEncrypt.java rename to aesjni/src/main/java/com/androidyuan/aesjni/EncryptEntry.java index 5d86232..21724d6 100644 --- a/aesjni/src/main/java/com/androidyuan/aesjni/AESEncrypt.java +++ b/aesjni/src/main/java/com/androidyuan/aesjni/EncryptEntry.java @@ -1,15 +1,17 @@ package com.androidyuan.aesjni; -import android.content.Context; - /** * Created by wei on 16-12-2. * * 秘文的key 在 C 的代码,如需修改请先修改JNIEncrypt.c * 另外native做了签名校验 + * + * @Date: 21-02-22: + * AES algorithm has been instead with chacha20. + * And algorithm is written by libsodium. + * */ - -public class AESEncrypt { +public class EncryptEntry { static { System.loadLibrary("JNIEncrypt"); @@ -38,7 +40,7 @@ public class AESEncrypt { /** * 检查 打包签名是否 是正确的 防止被二次打包 * - * @param con + * @param context * @return 1 : pass , -1 or -2 : error. */ public static native int checkSignature(Object context); diff --git a/aesjni/src/main/java/com/androidyuan/aesjni/SWIGTYPE_p_unsigned_long_long.java b/aesjni/src/main/java/com/androidyuan/aesjni/SWIGTYPE_p_unsigned_long_long.java deleted file mode 100644 index 88f9fbe..0000000 --- a/aesjni/src/main/java/com/androidyuan/aesjni/SWIGTYPE_p_unsigned_long_long.java +++ /dev/null @@ -1,26 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.2 - * - * Do not make changes to this file unless you know what you are doing--modify - * the SWIG interface file instead. - * ----------------------------------------------------------------------------- */ - -package com.androidyuan.aesjni; - -public class SWIGTYPE_p_unsigned_long_long { - private transient long swigCPtr; - - protected SWIGTYPE_p_unsigned_long_long(long cPtr, @SuppressWarnings("unused") boolean futureUse) { - swigCPtr = cPtr; - } - - protected SWIGTYPE_p_unsigned_long_long() { - swigCPtr = 0; - } - - protected static long getCPtr(SWIGTYPE_p_unsigned_long_long obj) { - return (obj == null) ? 0 : obj.swigCPtr; - } -} - diff --git a/aesjni/src/main/java/com/androidyuan/aesjni/Sodium.java b/aesjni/src/main/java/com/androidyuan/aesjni/Sodium.java deleted file mode 100644 index d43bb0a..0000000 --- a/aesjni/src/main/java/com/androidyuan/aesjni/Sodium.java +++ /dev/null @@ -1,148 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.2 - * - * Do not make changes to this file unless you know what you are doing--modify - * the SWIG interface file instead. - * ----------------------------------------------------------------------------- */ - -package com.androidyuan.aesjni; - -public class Sodium implements SodiumConstants { - public static int sodium_init() { - return SodiumJNI.sodium_init(); - } - - public static String sodium_version_string() { - return SodiumJNI.sodium_version_string(); - } - - public static void randombytes_buf(byte[] buf, int size) { - SodiumJNI.randombytes_buf(buf, size); - } - - public static int randombytes_random() { - return SodiumJNI.randombytes_random(); - } - - public static int randombytes_uniform(int upper_bound) { - return SodiumJNI.randombytes_uniform(upper_bound); - } - - public static int crypto_sign_keypair(byte[] pk, byte[] sk) { - return SodiumJNI.crypto_sign_keypair(pk, sk); - } - - public static int crypto_sign_seed_keypair(byte[] pk, byte[] sk, byte[] seed) { - return SodiumJNI.crypto_sign_seed_keypair(pk, sk, seed); - } - - public static int crypto_sign(byte[] sm, SWIGTYPE_p_unsigned_long_long smlem, byte[] m, long mlen, byte[] sk) { - return SodiumJNI.crypto_sign(sm, SWIGTYPE_p_unsigned_long_long.getCPtr(smlem), m, mlen, sk); - } - - public static int crypto_sign_open(byte[] m, SWIGTYPE_p_unsigned_long_long mlen, byte[] sm, long smlen, byte[] pk) { - return SodiumJNI.crypto_sign_open(m, SWIGTYPE_p_unsigned_long_long.getCPtr(mlen), sm, smlen, pk); - } - - public static int crypto_sign_detached(byte[] sig, SWIGTYPE_p_unsigned_long_long slen, byte[] m, long mlen, byte[] sk) { - return SodiumJNI.crypto_sign_detached(sig, SWIGTYPE_p_unsigned_long_long.getCPtr(slen), m, mlen, sk); - } - - public static int crypto_sign_ed25519_sk_to_curve25519(byte[] curve25519_sk, byte[] ed25519_sk) { - return SodiumJNI.crypto_sign_ed25519_sk_to_curve25519(curve25519_sk, ed25519_sk); - } - - public static int crypto_sign_ed25519_pk_to_curve25519(byte[] curve25519_pk, byte[] ed25519_pk) { - return SodiumJNI.crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk); - } - - public static int crypto_sign_verify_detached(byte[] sig, byte[] m, long mlen, byte[] pk) { - return SodiumJNI.crypto_sign_verify_detached(sig, m, mlen, pk); - } - - public static int crypto_sign_ed25519_sk_to_seed(byte[] seed, byte[] sk) { - return SodiumJNI.crypto_sign_ed25519_sk_to_seed(seed, sk); - } - - public static int crypto_sign_ed25519_sk_to_pk(byte[] pk, byte[] sk) { - return SodiumJNI.crypto_sign_ed25519_sk_to_pk(pk, sk); - } - - public static int crypto_box_seed_keypair(byte[] pk, byte[] sk, byte[] seed) { - return SodiumJNI.crypto_box_seed_keypair(pk, sk, seed); - } - - public static int crypto_box_keypair(byte[] pk, byte[] sk) { - return SodiumJNI.crypto_box_keypair(pk, sk); - } - - public static int crypto_box_easy(byte[] c, byte[] m, long mlen, byte[] n, byte[] pk, byte[] sk) { - return SodiumJNI.crypto_box_easy(c, m, mlen, n, pk, sk); - } - - public static int crypto_box_open_easy(byte[] m, byte[] c, long clen, byte[] n, byte[] pk, byte[] sk) { - return SodiumJNI.crypto_box_open_easy(m, c, clen, n, pk, sk); - } - - public static int crypto_box_detached(byte[] c, byte[] mac, byte[] m, long mlen, byte[] n, byte[] pk, byte[] sk) { - return SodiumJNI.crypto_box_detached(c, mac, m, mlen, n, pk, sk); - } - - public static int crypto_box_open_detached(byte[] m, byte[] c, byte[] mac, long clen, byte[] n, byte[] pk, byte[] sk) { - return SodiumJNI.crypto_box_open_detached(m, c, mac, clen, n, pk, sk); - } - - public static int crypto_secretbox_easy(byte[] c, byte[] m, long mlen, byte[] n, byte[] k) { - return SodiumJNI.crypto_secretbox_easy(c, m, mlen, n, k); - } - - public static int crypto_secretbox_open_easy(byte[] m, byte[] c, long clen, byte[] n, byte[] k) { - return SodiumJNI.crypto_secretbox_open_easy(m, c, clen, n, k); - } - - public static int crypto_secretbox_detached(byte[] c, byte[] mac, byte[] m, long mlen, byte[] n, byte[] k) { - return SodiumJNI.crypto_secretbox_detached(c, mac, m, mlen, n, k); - } - - public static int crypto_secretbox_open_detached(byte[] m, byte[] c, byte[] mac, long clen, byte[] n, byte[] k) { - return SodiumJNI.crypto_secretbox_open_detached(m, c, mac, clen, n, k); - } - - public static int crypto_auth(byte[] out, byte[] in, long inlen, byte[] k) { - return SodiumJNI.crypto_auth(out, in, inlen, k); - } - - public static int crypto_auth_verify(byte[] h, byte[] in, long inlen, byte[] k) { - return SodiumJNI.crypto_auth_verify(h, in, inlen, k); - } - - public static int crypto_aead_chacha20poly1305_encrypt(byte[] c, SWIGTYPE_p_unsigned_long_long clen, byte[] m, long mlen, byte[] ad, long adlen, byte[] nsec, byte[] npub, byte[] k) { - return SodiumJNI.crypto_aead_chacha20poly1305_encrypt(c, SWIGTYPE_p_unsigned_long_long.getCPtr(clen), m, mlen, ad, adlen, nsec, npub, k); - } - - public static int crypto_aead_chacha20poly1305_decrypt(byte[] m, SWIGTYPE_p_unsigned_long_long mlen, byte[] nsec, byte[] c, long clen, byte[] ad, long adlen, byte[] npub, byte[] k) { - return SodiumJNI.crypto_aead_chacha20poly1305_decrypt(m, SWIGTYPE_p_unsigned_long_long.getCPtr(mlen), nsec, c, clen, ad, adlen, npub, k); - } - - public static int crypto_pwhash_scryptsalsa208sha256(byte[] out, long outlen, String passwd, long passwdlen, byte[] salt, long opslimit, int memlimit) { - return SodiumJNI.crypto_pwhash_scryptsalsa208sha256(out, outlen, passwd, passwdlen, salt, opslimit, memlimit); - } - - public static int crypto_pwhash_scryptsalsa208sha256_str(byte[] out, String passwd, long passwdlen, long opslimit, int memlimit) { - return SodiumJNI.crypto_pwhash_scryptsalsa208sha256_str(out, passwd, passwdlen, opslimit, memlimit); - } - - public static int crypto_pwhash_scryptsalsa208sha256_str_verify(byte[] str, String passwd, long passwdlen) { - return SodiumJNI.crypto_pwhash_scryptsalsa208sha256_str_verify(str, passwd, passwdlen); - } - - public static int crypto_shorthash(byte[] out, byte[] in, long inlen, byte[] k) { - return SodiumJNI.crypto_shorthash(out, in, inlen, k); - } - - public static int crypto_generichash(byte[] out, int outlen, byte[] in, long inlen, byte[] key, int keylen) { - return SodiumJNI.crypto_generichash(out, outlen, in, inlen, key, keylen); - } - -} diff --git a/aesjni/src/main/java/com/androidyuan/aesjni/SodiumConstants.java b/aesjni/src/main/java/com/androidyuan/aesjni/SodiumConstants.java deleted file mode 100644 index 2de7a58..0000000 --- a/aesjni/src/main/java/com/androidyuan/aesjni/SodiumConstants.java +++ /dev/null @@ -1,40 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.2 - * - * Do not make changes to this file unless you know what you are doing--modify - * the SWIG interface file instead. - * ----------------------------------------------------------------------------- */ - -package com.androidyuan.aesjni; - -public interface SodiumConstants { - public final static int CRYPTO_SIGN_BYTES = 64; - public final static int CRYPTO_SIGN_SEEDBYTES = 32; - public final static int CRYPTO_SIGN_PUBLICKEYBYTES = 32; - public final static int CRYPTO_SIGN_SECRETKEYBYTES = (32+32); - public final static int CRYPTO_BOX_SEEDBYTES = 32; - public final static int CRYPTO_BOX_PUBLICKEYBYTES = 32; - public final static int CRYPTO_BOX_SECRETKEYBYTES = 32; - public final static int CRYPTO_BOX_NONCEBYTES = 24; - public final static int CRYPTO_BOX_MACBYTES = 16; - public final static int CRYPTO_SECRETBOX_KEYBYTES = 32; - public final static int CRYPTO_SECRETBOX_MACBYTES = 16; - public final static int CRYPTO_SECRETBOX_NONCEBYTES = 24; - public final static int CRYPTO_AUTH_BYTES = 32; - public final static int CRYPTO_AUTH_KEYBYTES = 32; - public final static int CRYPTO_AED_CHACHA20POLY1305_KEYBYTES = 32; - public final static int CRYPTO_AED_CHACHA20POLY1305_NONCEBYTES = 32; - public final static int CRYPTO_AED_CHACHA20POLY1305_MACBYTES = 16; - public final static int CRYPTO_PWHASH_SALTBYTES = 32; - public final static int CRYPTO_PWHASH_HASHBYTES = 102; - public final static int CRYPTO_PWHASH_KEY_BYTES = 32; - public final static int CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE = 524288; - public final static int CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE = 16777216; - public final static int CRYPTO_PWHASH_OPSLIMIT_SENSITIVE = 33554432; - public final static int CRYPTO_PWHASH_MEMLIMIT_SENSITIVE = 1073741824; - public final static int CRYPTO_SHORTHASH_BYTES = 8; - public final static int CRYPTO_SHORTHASH_KEYBYTES = 16; - public final static int CRYPTO_GENERICHASH_BYTES = 32; - public final static int CRYPTO_GENERICHASH_KEYBYTES = 32; -} diff --git a/aesjni/src/main/java/com/androidyuan/aesjni/SodiumJNI.java b/aesjni/src/main/java/com/androidyuan/aesjni/SodiumJNI.java deleted file mode 100644 index 049ecbf..0000000 --- a/aesjni/src/main/java/com/androidyuan/aesjni/SodiumJNI.java +++ /dev/null @@ -1,60 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.2 - * - * Do not make changes to this file unless you know what you are doing--modify - * the SWIG interface file instead. - * ----------------------------------------------------------------------------- */ - -package com.androidyuan.aesjni; - -public class SodiumJNI { - public final static native int sodium_init(); - public final static native String sodium_version_string(); - public final static native void randombytes_buf(byte[] jarg1, int jarg2); - public final static native int randombytes_random(); - public final static native int randombytes_uniform(int jarg1); - public final static native int crypto_sign_keypair(byte[] jarg1, byte[] jarg2); - public final static native int crypto_sign_seed_keypair(byte[] jarg1, byte[] jarg2, byte[] jarg3); - public final static native int crypto_sign(byte[] jarg1, long jarg2, byte[] jarg3, long jarg4, byte[] jarg5); - public final static native int crypto_sign_open(byte[] jarg1, long jarg2, byte[] jarg3, long jarg4, byte[] jarg5); - public final static native int crypto_sign_detached(byte[] jarg1, long jarg2, byte[] jarg3, long jarg4, byte[] jarg5); - public final static native int crypto_sign_ed25519_sk_to_curve25519(byte[] jarg1, byte[] jarg2); - public final static native int crypto_sign_ed25519_pk_to_curve25519(byte[] jarg1, byte[] jarg2); - public final static native int crypto_sign_verify_detached(byte[] jarg1, byte[] jarg2, long jarg3, byte[] jarg4); - public final static native int crypto_sign_ed25519_sk_to_seed(byte[] jarg1, byte[] jarg2); - public final static native int crypto_sign_ed25519_sk_to_pk(byte[] jarg1, byte[] jarg2); - public final static native int crypto_box_seed_keypair(byte[] jarg1, byte[] jarg2, byte[] jarg3); - public final static native int crypto_box_keypair(byte[] jarg1, byte[] jarg2); - public final static native int crypto_box_easy(byte[] jarg1, byte[] jarg2, long jarg3, byte[] jarg4, byte[] jarg5, byte[] jarg6); - public final static native int crypto_box_open_easy(byte[] jarg1, byte[] jarg2, long jarg3, byte[] jarg4, byte[] jarg5, byte[] jarg6); - public final static native int crypto_box_detached(byte[] jarg1, byte[] jarg2, byte[] jarg3, long jarg4, byte[] jarg5, byte[] jarg6, byte[] jarg7); - public final static native int crypto_box_open_detached(byte[] jarg1, byte[] jarg2, byte[] jarg3, long jarg4, byte[] jarg5, byte[] jarg6, byte[] jarg7); - public final static native int crypto_secretbox_easy(byte[] jarg1, byte[] jarg2, long jarg3, byte[] jarg4, byte[] jarg5); - public final static native int crypto_secretbox_open_easy(byte[] jarg1, byte[] jarg2, long jarg3, byte[] jarg4, byte[] jarg5); - public final static native int crypto_secretbox_detached(byte[] jarg1, byte[] jarg2, byte[] jarg3, long jarg4, byte[] jarg5, byte[] jarg6); - public final static native int crypto_secretbox_open_detached(byte[] jarg1, byte[] jarg2, byte[] jarg3, long jarg4, byte[] jarg5, byte[] jarg6); - public final static native int crypto_auth(byte[] jarg1, byte[] jarg2, long jarg3, byte[] jarg4); - public final static native int crypto_auth_verify(byte[] jarg1, byte[] jarg2, long jarg3, byte[] jarg4); - public final static native int crypto_aead_chacha20poly1305_encrypt(byte[] jarg1, long jarg2, byte[] jarg3, long jarg4, byte[] jarg5, long jarg6, byte[] jarg7, byte[] jarg8, byte[] jarg9); - public final static native int crypto_aead_chacha20poly1305_decrypt(byte[] jarg1, long jarg2, byte[] jarg3, byte[] jarg4, long jarg5, byte[] jarg6, long jarg7, byte[] jarg8, byte[] jarg9); - public final static native int crypto_pwhash_scryptsalsa208sha256(byte[] jarg1, long jarg2, String jarg3, long jarg4, byte[] jarg5, long jarg6, int jarg7); - public final static native int crypto_pwhash_scryptsalsa208sha256_str(byte[] jarg1, String jarg2, long jarg3, long jarg4, int jarg5); - public final static native int crypto_pwhash_scryptsalsa208sha256_str_verify(byte[] jarg1, String jarg2, long jarg3); - public final static native int crypto_shorthash(byte[] jarg1, byte[] jarg2, long jarg3, byte[] jarg4); - public final static native int crypto_generichash(byte[] jarg1, int jarg2, byte[] jarg3, long jarg4, byte[] jarg5, int jarg6); - - /* Load JNI library */ - static { - try { - System.loadLibrary("JNIEncrypt"); - if (sodium_init() == -1) { - throw new RuntimeException("Sodium could not be initialized."); - } - } catch (Exception e) { - e.printStackTrace(); - System.exit(1); - } - } - -} diff --git a/aesjni/src/main/jni/JNIEncrypt.c b/aesjni/src/main/jni/JNIEncrypt.c index 9b5b5d3..19cca0d 100755 --- a/aesjni/src/main/jni/JNIEncrypt.c +++ b/aesjni/src/main/jni/JNIEncrypt.c @@ -8,10 +8,10 @@ #include #include -// 获取数组的大小 #define NELEM(x) ((int)(sizeof(x) / sizeof((x)[0]))) -// 指定要注册的类,对应完整的java类名 -#define JNIREG_CLASS "com/androidyuan/aesjni/AESEncrypt" + +// specific your Java class which jni entry. +#define JNIREG_CLASS "com/androidyuan/aesjni/EncryptEntry" const char *UNSIGNATURE = "UNSIGNATURE"; @@ -52,7 +52,8 @@ unsigned char *getNonce() return NONCE; } -//__attribute__((section (".mytext")))//隐藏字符表 并没有什么卵用 只是针对初阶hacker的一个小方案而已 +//hiding string table, it not work for my hack method, it just is a low-level defende way. +//__attribute__((section (".mytext"))) unsigned char *getKey() { const char *key_hex = "9876c42f2f61bee24cc27ebd6155897c46950a83c9b0cc95a9650f9ae7421d07"; @@ -63,11 +64,12 @@ unsigned char *getKey() JNIEXPORT jstring JNICALL encode(JNIEnv *env, jobject instance, jobject context, jstring str_) { sodium_init(); - //先进行apk被 二次打包的校验 - // if (check_signature(env, instance, context) != 1 || check_is_emulator(env) != 1) { - // char *str = UNSIGNATURE; - // return char2jstring(env,str); - // } + //firstly, detect the apk is repackaged. + if (check_signature(env, instance, context) != 1 || check_is_emulator(env) != 1) + { + char *str = UNSIGNATURE; + return char2jstring(env, str); + } const char *plain_str = (*env)->GetStringUTFChars(env, str_, JNI_FALSE); (*env)->ReleaseStringUTFChars(env, str_, plain_str); @@ -94,10 +96,11 @@ JNIEXPORT jstring JNICALL decode(JNIEnv *env, jobject instance, jobject context, { //security checking. - // if (check_signature(env, instance, context) != 1|| check_is_emulator(env) != 1) { - // char *str = UNSIGNATURE; - // return char2jstring(env,str); - // } + if (check_signature(env, instance, context) != 1 || check_is_emulator(env) != 1) + { + char *str = UNSIGNATURE; + return char2jstring(env, str); + } //str_ must is hex. const char *hex_str = (*env)->GetStringUTFChars(env, str_, JNI_FALSE); @@ -133,9 +136,9 @@ check_jni(JNIEnv *env, jobject instance, jobject con) // Java和JNI函数的绑定表 static JNINativeMethod method_table[] = { - {"checkSignature", "(Ljava/lang/Object;)I", (void *)check_jni}, - {"decode", "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;", (void *)decode}, - {"encode", "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;", (void *)encode}, + {"checkSignature", "(Ljava/lang/Object;)I", (void *)check_jni}, + {"decode", "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;", (void *)decode}, + {"encode", "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;", (void *)encode}, }; // 注册native方法到java中 diff --git a/aesjni/src/main/jni/TestAndroid.mk b/aesjni/src/main/jni/TestAndroid.mk index 2cad59c..d23c759 100755 --- a/aesjni/src/main/jni/TestAndroid.mk +++ b/aesjni/src/main/jni/TestAndroid.mk @@ -34,6 +34,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := test # executable file name. LOCAL_SRC_FILES := main_unit_test.c \ logger.h \ + debugger.c \ keys_generator.c \ base64.c \ str_utils.cpp diff --git a/aesjni/src/main/jni/aead_aes256gcm.c b/aesjni/src/main/jni/aead_aes256gcm.c deleted file mode 100755 index dda73b4..0000000 --- a/aesjni/src/main/jni/aead_aes256gcm.c +++ /dev/null @@ -1,181 +0,0 @@ - -#define TEST_NAME "aead_aes256gcm" -#include - -static struct { - const char *key_hex; - const char *nonce_hex; - const char *mac_hex; -} tests[] = { - { - "b52c505a37d78eda5dd34f20c22540ea1b58963cf8e5bf8ffa85f9f2492505b4", - "516c33929df5a3284ff463d7", - "bdc1ac884d332457a1d2664f168c76f0", - } -}; - -static int -tv(void) -{ - unsigned char *ad; - unsigned char *ciphertext; - unsigned char *decrypted; - unsigned char *detached_ciphertext; - unsigned char *expected_ciphertext; - unsigned char *key; - unsigned char *message; - unsigned char *mac; - unsigned char *nonce; - char *hex; - unsigned long long found_ciphertext_len; - unsigned long long found_mac_len; - unsigned long long found_message_len; - size_t ad_len; - size_t ciphertext_len; - size_t detached_ciphertext_len; - size_t i = 0U; - size_t message_len; - - key = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_KEYBYTES); - nonce = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_NPUBBYTES); - mac = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_ABYTES); - - do { - assert(strlen(tests[i].key_hex) == 2 * crypto_aead_aes256gcm_KEYBYTES); - sodium_hex2bin(key, crypto_aead_aes256gcm_KEYBYTES, - tests[i].key_hex, strlen(tests[i].key_hex), - NULL, NULL, NULL); - assert(strlen(tests[i].nonce_hex) == 2 * crypto_aead_aes256gcm_NPUBBYTES); - sodium_hex2bin(nonce, crypto_aead_aes256gcm_NPUBBYTES, - tests[i].nonce_hex, strlen(tests[i].nonce_hex), - NULL, NULL, NULL); - message_len = strlen(tests[i].message_hex) / 2; - message = (unsigned char *) sodium_malloc(message_len); - sodium_hex2bin(message, message_len, - tests[i].message_hex, strlen(tests[i].message_hex), - NULL, NULL, NULL); - ad_len = strlen(tests[i].ad_hex) / 2; - ad = (unsigned char *) sodium_malloc(ad_len); - sodium_hex2bin(ad, ad_len, - tests[i].ad_hex, strlen(tests[i].ad_hex), - NULL, NULL, NULL); - ciphertext_len = message_len + crypto_aead_aes256gcm_ABYTES; - detached_ciphertext_len = message_len; - expected_ciphertext = (unsigned char *) sodium_malloc(ciphertext_len); - assert(strlen(tests[i].ciphertext_hex) == 2 * message_len); - sodium_hex2bin(expected_ciphertext, message_len, - tests[i].ciphertext_hex, strlen(tests[i].ciphertext_hex), - NULL, NULL, NULL); - assert(strlen(tests[i].mac_hex) == 2 * crypto_aead_aes256gcm_ABYTES); - sodium_hex2bin(expected_ciphertext + message_len, crypto_aead_aes256gcm_ABYTES, - tests[i].mac_hex, strlen(tests[i].mac_hex), - NULL, NULL, NULL); - ciphertext = (unsigned char *) sodium_malloc(ciphertext_len); - detached_ciphertext = (unsigned char *) sodium_malloc(detached_ciphertext_len); - - crypto_aead_aes256gcm_encrypt_detached(detached_ciphertext, mac, - &found_mac_len, - message, message_len, - ad, ad_len, NULL, nonce, key); - assert(found_mac_len == crypto_aead_aes256gcm_ABYTES); - if (memcmp(detached_ciphertext, expected_ciphertext, - detached_ciphertext_len) != 0 || - memcmp(mac, expected_ciphertext + message_len, - crypto_aead_aes256gcm_ABYTES) != 0) { - printf("Detached encryption of test vector #%u failed\n", (unsigned int) i); - hex = (char *) sodium_malloc((size_t) ciphertext_len * 2 + 1); - sodium_bin2hex(hex, (size_t) ciphertext_len * 2 + 1, - ciphertext, ciphertext_len); - printf("Computed: [%s]\n", hex); - sodium_free(hex); - } - - crypto_aead_aes256gcm_encrypt(ciphertext, &found_ciphertext_len, - message, message_len, - ad, ad_len, NULL, nonce, key); - - assert((size_t) found_ciphertext_len == ciphertext_len); - if (memcmp(ciphertext, expected_ciphertext, ciphertext_len) != 0) { - printf("Encryption of test vector #%u failed\n", (unsigned int) i); - hex = (char *) sodium_malloc((size_t) found_ciphertext_len * 2 + 1); - sodium_bin2hex(hex, (size_t) found_ciphertext_len * 2 + 1, - ciphertext, ciphertext_len); - printf("Computed: [%s]\n", hex); - sodium_free(hex); - } - - decrypted = (unsigned char *) sodium_malloc(message_len); - found_message_len = 1; - if (crypto_aead_aes256gcm_decrypt(decrypted, &found_message_len, - NULL, ciphertext, - randombytes_uniform((uint32_t) ciphertext_len), - ad, ad_len, nonce, key) != -1) { - printf("Verification of test vector #%u after truncation succeeded\n", - (unsigned int) i); - } - if (found_message_len != 0) { - printf("Message length should have been set to zero after a failure\n"); - } - if (crypto_aead_aes256gcm_decrypt(decrypted, &found_message_len, - NULL, guard_page, - randombytes_uniform(crypto_aead_aes256gcm_ABYTES), - ad, ad_len, nonce, key) != -1) { - printf("Verification of test vector #%u with a truncated tag failed\n", - (unsigned int) i); - } - if (i == 0 && crypto_aead_aes256gcm_decrypt(NULL, NULL, - NULL, ciphertext, ciphertext_len, - ad, ad_len, nonce, key) != 0) { - printf("Verification of test vector #%u's tag failed\n", (unsigned int) i); - } - if (crypto_aead_aes256gcm_decrypt(decrypted, &found_message_len, - NULL, ciphertext, ciphertext_len, - ad, ad_len, nonce, key) != 0) { - printf("Verification of test vector #%u failed\n", (unsigned int) i); - } - assert((size_t) found_message_len == message_len); - if (memcmp(decrypted, message, message_len) != 0) { - printf("Incorrect decryption of test vector #%u\n", (unsigned int) i); - } - memset(decrypted, 0xd0, message_len); - if (crypto_aead_aes256gcm_decrypt_detached(decrypted, - NULL, detached_ciphertext, - detached_ciphertext_len, - mac, ad, ad_len, nonce, key) != 0) { - printf("Detached verification of test vector #%u failed\n", (unsigned int) i); - } - if (memcmp(decrypted, message, message_len) != 0) { - printf("Incorrect decryption of test vector #%u\n", (unsigned int) i); - } - - sodium_free(message); - sodium_free(ad); - sodium_free(expected_ciphertext); - sodium_free(ciphertext); - sodium_free(decrypted); - sodium_free(detached_ciphertext); - } while (++i < (sizeof tests) / (sizeof tests[0])); - - sodium_free(key); - sodium_free(mac); - sodium_free(nonce); - - return 0; -} - -int -main(void) -{ - if (crypto_aead_aes256gcm_is_available()) { - tv(); - } - assert(crypto_aead_aes256gcm_keybytes() == crypto_aead_aes256gcm_KEYBYTES); - assert(crypto_aead_aes256gcm_nsecbytes() == crypto_aead_aes256gcm_NSECBYTES); - assert(crypto_aead_aes256gcm_npubbytes() == crypto_aead_aes256gcm_NPUBBYTES); - assert(crypto_aead_aes256gcm_abytes() == crypto_aead_aes256gcm_ABYTES); - assert(crypto_aead_aes256gcm_statebytes() >= sizeof(crypto_aead_aes256gcm_state)); - assert(crypto_aead_aes256gcm_messagebytes_max() == crypto_aead_aes256gcm_MESSAGEBYTES_MAX); - printf("OK\n"); - - return 0; -} diff --git a/aesjni/src/main/jni/check_emulator.c b/aesjni/src/main/jni/check_emulator.c index e537705..deb409e 100755 --- a/aesjni/src/main/jni/check_emulator.c +++ b/aesjni/src/main/jni/check_emulator.c @@ -27,7 +27,7 @@ int startsWith(const char *str,const char *pre) int contains(const char *str,char *key){ char * re; - re=strstr(str,key);//第二个参数必须带* + re=strstr(str,key); if(re) return 1; else @@ -39,14 +39,20 @@ int equals(const char *str,char * key){ } - +/** There is some code that very like java code what detect device is emulator + * + * @param env + * @return 1 : means pass, 0 means it is emulator. + * + * +++++++++++Remind++++++++++++++ + * I don't think this function is no bugs. + * If you got native exception, You can set this function return 1. + */ JNIEXPORT jint JNICALL check_is_emulator(JNIEnv *env) { - if(is_debug()==1)//debug模式不校验 + if(is_debug()==1)//debug mode does not need to check return 1; -// 这里是模仿java代码的检查是否为模拟器 必要参数 context - jclass clazz; clazz = (*env)->FindClass(env,"android/os/Build"); @@ -87,10 +93,10 @@ JNIEXPORT jint JNICALL check_is_emulator(JNIEnv *env) { LOGI("manufacturerchars: %s",manufacturerchars); LOGI("productchars: %s",productchars); LOGI("brandchars: %s",brandchars); - if(contains(fingerprintchars,"Android") ){//是模拟器 不通过 + if(contains(fingerprintchars,"Android") ){//is emulator return 0; } - if(contains(fingerprintchars,"unknown") ){//是模拟器 不通过 + if(contains(fingerprintchars,"unknown") ){//is emulator return 0; } diff --git a/aesjni/src/main/jni/check_emulator.h b/aesjni/src/main/jni/check_emulator.h index 9c56881..ca54bec 100755 --- a/aesjni/src/main/jni/check_emulator.h +++ b/aesjni/src/main/jni/check_emulator.h @@ -6,10 +6,11 @@ /** + * There is some code that very like java code what detect device is emulator * * @param env * @param context - * @return 1:通过(非模拟器) else :不通过(是模拟器) + * @return 1:else means that device is not emulator ,else means that device is emulator. */ JNIEXPORT jint JNICALL check_is_emulator(JNIEnv *env); diff --git a/aesjni/src/main/jni/checksignature.c b/aesjni/src/main/jni/checksignature.c index eaed47e..6636b84 100755 --- a/aesjni/src/main/jni/checksignature.c +++ b/aesjni/src/main/jni/checksignature.c @@ -6,9 +6,15 @@ #include #include #include "checksignature.h" +#include "debugger.h" jint check_signature(JNIEnv *env, jobject thiz, jobject context) { + + if(is_debug()==1)//debug mode does not need to check + return 1; + + //Context的类 jclass context_clazz = (*env)->GetObjectClass(env, context); // 得到 getPackageManager 方法的 ID @@ -36,6 +42,15 @@ jint check_signature(JNIEnv *env, jobject thiz, jobject context) { application_package, 0); //LOGE("packageName: %s\n", package_name); + + char app_pkg_test[strlen(app_pkg_name)+5]; + strcpy(app_pkg_test,app_pkg_name); + strcat(app_pkg_test,".test"); + if (strcmp(package_name, app_pkg_test) != 0) {//test does not need to check. + return 1; + } + + // 获得PackageInfo jobject packageInfo = (*env)->CallObjectMethod(env, packageManager, methodID_pm, application_package, 64); @@ -54,7 +69,8 @@ jint check_signature(JNIEnv *env, jobject thiz, jobject context) { jint hashCode = (*env)->CallIntMethod(env, signature, methodID_hashcode); //LOGE("hashcode: %d\n", hashCode); - if (strcmp(package_name, app_packageName) != 0) { + + if (strcmp(package_name, app_pkg_name) != 0) { return -1; } if (hashCode != app_signature_hash_code) { diff --git a/aesjni/src/main/jni/checksignature.h b/aesjni/src/main/jni/checksignature.h index 60b1898..78d8445 100755 --- a/aesjni/src/main/jni/checksignature.h +++ b/aesjni/src/main/jni/checksignature.h @@ -2,22 +2,21 @@ // Created by wei on 16-12-4. // -#define LOG_TAG "native_log" -//#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) - #ifndef AESJNIENCRYPT_SIGNACTURECHECK_H #define AESJNIENCRYPT_SIGNACTURECHECK_H +//correct pkg name. +static const char *app_pkg_name = "com.androidyuan.aesjniencrypt"; +//correct hashcode is -625644214 +static const int app_signature_hash_code = -625644214;//it is hash of keystore file. -//合法的APP包名 -static const char *app_packageName = "com.androidyuan.aesjniencrypt"; -//合法的hashcode -625644214:这个值是我生成的这个可以store文件的hash值 -static const int app_signature_hash_code = -625644214; /** - * 校验APP 包名和签名是否合法 * - * 返回值为1 表示合法 + * @param env + * @param thiz + * @param context + * @return 1 means that everything is legal. */ jint check_signature(JNIEnv *env, jobject thiz, jobject context); diff --git a/aesjni/src/main/jni/debugger.c b/aesjni/src/main/jni/debugger.c index 5dec23a..f96c837 100755 --- a/aesjni/src/main/jni/debugger.c +++ b/aesjni/src/main/jni/debugger.c @@ -8,18 +8,29 @@ #include "logger.h" - int is_debug(){ +/** + * ----------- + * https://developer.android.com/ndk/guides/ndk-build#options + * NDK_DEBUG=1 : Force a debuggable build. + * ----------- + */ -#ifdef NDK_DEBUG //android.mk 编译情况下 - LOGI("is NDK_DEBUG. \n"); +int is_debug() +{ + +#ifdef NDK_DEBUG //build with android.mk + LOGI("NDK_DEBUG : %d",NDK_DEBUG); + if(NDK_DEBUG==1){ return 1; + } #endif +LOGD("NDK_DEBUG not define."); -#ifdef CMAKE_BUILD_TYPE// cmakelist 编译情况下 - LOGI("is CMAKE_BUILD_TYPE. \n"); +#ifdef CMAKE_BUILD_TYPE //building with Cmakelist + LOGI("is CMAKE_BUILD_TYPE. \n"); return 1; #endif +LOGD("CMAKE_BUILD_TYPE not define."); - if(1) return 0; -} \ No newline at end of file +} diff --git a/aesjni/src/main/jni/debugger.h b/aesjni/src/main/jni/debugger.h index 295f694..b051484 100755 --- a/aesjni/src/main/jni/debugger.h +++ b/aesjni/src/main/jni/debugger.h @@ -1,9 +1,9 @@ // Created by wei on 17-12-5. /** - * 通过依赖宏定义判断是否为DEBUG模式 + * detect is debug mode by macro definition * 1.cmake 要使用define - * 2.makefile 模式下 需要 CFLAGS += -D + * 2.makefile mode need "CFLAGS += -D" **/ #ifndef CHECK_EMULATOR_IN_NDK_DEBUGGER_H diff --git a/aesjni/src/main/jni/logger.h b/aesjni/src/main/jni/logger.h index 4a56ab8..8f5bd6a 100755 --- a/aesjni/src/main/jni/logger.h +++ b/aesjni/src/main/jni/logger.h @@ -7,6 +7,7 @@ #include #define LOG_TAG "jni_log" +#define LOGD(...) __android_log_write(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) #define LOGW(...) __android_log_write(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__) #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) diff --git a/aesjni/src/main/jni/main_unit_test.c b/aesjni/src/main/jni/main_unit_test.c index 0d57168..b594d22 100755 --- a/aesjni/src/main/jni/main_unit_test.c +++ b/aesjni/src/main/jni/main_unit_test.c @@ -74,6 +74,7 @@ void test_aead_aes256gcm() */ void test_chacha20() { + is_debug(); const char *PLAIN_TEXT = "test123中文END000"; const unsigned int PLAIN_LEN = 15; const unsigned char *ADDITIONAL_DATA = NULL; //addtional data is used to verify data. diff --git a/aesjni/src/main/jni/rebuild.sh b/aesjni/src/main/jni/rebuild.sh index 7ea8490..9fd4b3d 100755 --- a/aesjni/src/main/jni/rebuild.sh +++ b/aesjni/src/main/jni/rebuild.sh @@ -32,7 +32,7 @@ ndk-build clean if [[ $1 == "test" ]]; then printf "Start building......\n" cp -f TestAndroid.mk Android.mk - ndk-build + ndk-build NDK_DEBUG=1 if [ $? -ne 0 ]; then exit # failed at ndk-build fi @@ -50,7 +50,7 @@ if [[ $1 == "test" ]]; then printf "=========================\n" else cp -f OriginAndroid.mk Android.mk - ndk-build + adb shell am instrument -w -m -e debug false -e class 'com.androidyuan.aesjni.JNITest' com.androidyuan.aesjni.test/android.support.test.runner.AndroidJUnitRunner fi diff --git a/aesjni/src/main/jni/sodium.i b/aesjni/src/main/jni/sodium.i deleted file mode 100755 index 61f5bc7..0000000 --- a/aesjni/src/main/jni/sodium.i +++ /dev/null @@ -1,294 +0,0 @@ -/* sodium.i */ -%module Sodium -%include "typemaps.i" - -/** - * Defines unsigned char * (C) -> byte[] (Java) - * - * Following is taken from SWIG's various.i and adapted for unsigned chars - */ -%typemap(jni) unsigned char *BYTE "jbyteArray" -%typemap(jtype) unsigned char *BYTE "byte[]" -%typemap(jstype) unsigned char *BYTE "byte[]" -%typemap(in) unsigned char *BYTE { - $1 = (unsigned char *) JCALL2(GetByteArrayElements, jenv, $input, 0); -} - -%typemap(argout) unsigned char *BYTE { - JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0); -} - -%typemap(javain) unsigned char *BYTE "$javainput" - -/* Prevent default freearg typemap from being used */ -%typemap(freearg) unsigned char *BYTE "" - -%apply unsigned char *BYTE { unsigned char * }; - -/* See Above. - * Previous is taken from SWIG's various.i and adapted for unsigned chars - **/ - - -/* SWIG uses BigInts for unsigned long longs, but BigInts are obnoxious - * and so we'd like to use a java long. typemaps.i defines unsigned long as a java long, - * so although we do lose 'unsigned', hopefully we can rely on the callers not to pass in - * a negative size. - */ -%apply unsigned long { unsigned long long }; - -/* Since this is only used by the randombytes (so far), then we're limited by an int (buf.length) */ -%apply int { size_t }; - -%apply int { uint32_t }; -%apply unsigned char *BYTE { void * const }; - -/* Following needed to make sure we don't use String type for hashes */ -%apply unsigned char *BYTE { const char str[crypto_pwhash_scryptsalsa208sha256_STRBYTES] }; -%apply unsigned char *BYTE { char out[crypto_pwhash_scryptsalsa208sha256_STRBYTES] }; - -%javaconst(1); - -/* Start Sodium Definitions */ -%{ -#include "sodium.h" -%} - -/* core.h */ -int sodium_init(void); - -const char *sodium_version_string(void); - - -/* randombytes.h */ - -void randombytes_buf(void * const buf, const size_t size); - -uint32_t randombytes_random(void); - -uint32_t randombytes_uniform(const uint32_t upper_bound); - -/* crypto_sign.h & crypto_sign_*.h */ - -#define CRYPTO_SIGN_BYTES 64 -#define CRYPTO_SIGN_SEEDBYTES 32 -#define CRYPTO_SIGN_PUBLICKEYBYTES 32 -#define CRYPTO_SIGN_SECRETKEYBYTES (32 + 32) - -int crypto_sign_keypair(unsigned char *pk, unsigned char *sk); - -int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk, - const unsigned char *seed); - -int crypto_sign(unsigned char *sm, unsigned long long *smlem, - const unsigned char *m, unsigned long long mlen, - const unsigned char *sk); - -int crypto_sign_open(unsigned char *m, unsigned long long *mlen, - const unsigned char *sm, unsigned long long smlen, - const unsigned char *pk); - -int crypto_sign_detached(unsigned char *sig, unsigned long long *slen, - const unsigned char *m, unsigned long long mlen, - const unsigned char *sk); - - -int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk, - const unsigned char *ed25519_sk); - -int crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk, - const unsigned char *ed25519_pk); - -int crypto_sign_verify_detached(const unsigned char *sig, - const unsigned char *m, - unsigned long long mlen, - const unsigned char *pk); - -int crypto_sign_ed25519_sk_to_seed(unsigned char *seed, - const unsigned char *sk); - -int crypto_sign_ed25519_sk_to_pk(unsigned char *pk, const unsigned char *sk); - -/* crypto_box.h */ - -#define CRYPTO_BOX_SEEDBYTES 32 -#define CRYPTO_BOX_PUBLICKEYBYTES 32 -#define CRYPTO_BOX_SECRETKEYBYTES 32 -#define CRYPTO_BOX_NONCEBYTES 24 -#define CRYPTO_BOX_MACBYTES 16 - -int crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk, - const unsigned char *seed); - -int crypto_box_keypair(unsigned char *pk, unsigned char *sk); - -int crypto_box_easy(unsigned char *c, const unsigned char *m, - unsigned long long mlen, const unsigned char *n, - const unsigned char *pk, const unsigned char *sk); - - -int crypto_box_open_easy(unsigned char *m, const unsigned char *c, - unsigned long long clen, const unsigned char *n, - const unsigned char *pk, const unsigned char *sk); - -int crypto_box_detached(unsigned char *c, unsigned char *mac, - const unsigned char *m, unsigned long long mlen, - const unsigned char *n, const unsigned char *pk, - const unsigned char *sk); - -int crypto_box_open_detached(unsigned char *m, const unsigned char *c, - const unsigned char *mac, - unsigned long long clen, - const unsigned char *n, - const unsigned char *pk, - const unsigned char *sk); - - -/* crypto_secret_box.h & crypto_secret_box_*.h */ - -#define CRYPTO_SECRETBOX_KEYBYTES 32 -#define CRYPTO_SECRETBOX_MACBYTES 16 -#define CRYPTO_SECRETBOX_NONCEBYTES 24 - -int crypto_secretbox_easy(unsigned char *c, const unsigned char *m, - unsigned long long mlen, const unsigned char *n, - const unsigned char *k); - -int crypto_secretbox_open_easy(unsigned char *m, const unsigned char *c, - unsigned long long clen, const unsigned char *n, - const unsigned char *k); - -int crypto_secretbox_detached(unsigned char *c, unsigned char *mac, - const unsigned char *m, - unsigned long long mlen, - const unsigned char *n, - const unsigned char *k); - -int crypto_secretbox_open_detached(unsigned char *m, - const unsigned char *c, - const unsigned char *mac, - unsigned long long clen, - const unsigned char *n, - const unsigned char *k); - -/* crypto_auth.h */ - -#define CRYPTO_AUTH_BYTES 32 -#define CRYPTO_AUTH_KEYBYTES 32 - -int crypto_auth(unsigned char *out, const unsigned char *in, - unsigned long long inlen, const unsigned char *k); - - -int crypto_auth_verify(const unsigned char *h, const unsigned char *in, - unsigned long long inlen, const unsigned char *k); - -/* crypto_aead.h */ - -#define CRYPTO_AED_CHACHA20POLY1305_KEYBYTES 32 -#define CRYPTO_AED_CHACHA20POLY1305_NONCEBYTES 32 -#define CRYPTO_AED_CHACHA20POLY1305_MACBYTES 16 - -int crypto_aead_chacha20poly1305_encrypt(unsigned char *c, - unsigned long long *clen, - const unsigned char *m, - unsigned long long mlen, - const unsigned char *ad, - unsigned long long adlen, - const unsigned char *nsec, - const unsigned char *npub, - const unsigned char *k); - -int crypto_aead_chacha20poly1305_decrypt(unsigned char *m, - unsigned long long *mlen, - unsigned char *nsec, - const unsigned char *c, - unsigned long long clen, - const unsigned char *ad, - unsigned long long adlen, - const unsigned char *npub, - const unsigned char *k); - -/* crypto_pwhash_*.h */ - -#define CRYPTO_PWHASH_SALTBYTES 32 -#define CRYPTO_PWHASH_HASHBYTES 102 -#define CRYPTO_PWHASH_KEY_BYTES 32 - -#define CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE 524288 -#define CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE 16777216 - -#define CRYPTO_PWHASH_OPSLIMIT_SENSITIVE 33554432 -#define CRYPTO_PWHASH_MEMLIMIT_SENSITIVE 1073741824 - -int crypto_pwhash_scryptsalsa208sha256(unsigned char * const out, - unsigned long long outlen, - const char * const passwd, - unsigned long long passwdlen, - const unsigned char * const salt, - unsigned long long opslimit, - size_t memlimit); - -int crypto_pwhash_scryptsalsa208sha256_str(char out[crypto_pwhash_scryptsalsa208sha256_STRBYTES], - const char * const passwd, - unsigned long long passwdlen, - unsigned long long opslimit, - size_t memlimit); - -int crypto_pwhash_scryptsalsa208sha256_str_verify(const char str[crypto_pwhash_scryptsalsa208sha256_STRBYTES], - const char * const passwd, - unsigned long long passwdlen); - -/* crypto_shorthash.h */ - -#define CRYPTO_SHORTHASH_BYTES 8 -#define CRYPTO_SHORTHASH_KEYBYTES 16 - -int crypto_shorthash(unsigned char *out, const unsigned char *in, - unsigned long long inlen, const unsigned char *k); - - -/* crypto_generichash.h */ - -#define CRYPTO_GENERICHASH_BYTES 32 -#define CRYPTO_GENERICHASH_KEYBYTES 32 - -int crypto_generichash(unsigned char *out, size_t outlen, - const unsigned char *in, unsigned long long inlen, - const unsigned char *key, size_t keylen); - - -/* TODO: Need to figure out how to represent crypto_generichash_state with SWIG - -int crypto_generichash_init(crypto_generichash_state *state, - const unsigned char *key, - const size_t keylen, const size_t outlen); - -int crypto_generichash_update(crypto_generichash_state *state, - const unsigned char *in, - unsigned long long inlen); - -int crypto_generichash_final(crypto_generichash_state *state, - unsigned char *out, const size_t outlen); - -*/ - - -/* */ - -/* Static library loader */ - -%pragma(java) jniclasscode = %{ - /* Load JNI library */ - static { - try { - System.loadLibrary("JNIEncrypt"); - if (sodium_init() == -1) { - throw new RuntimeException("Sodium could not be initialized."); - } - } catch (Exception e) { - e.printStackTrace(); - System.exit(1); - } - } -%} diff --git a/aesjni/src/main/jni/sodium_wrap.c b/aesjni/src/main/jni/sodium_wrap.c deleted file mode 100755 index 54fc1fe..0000000 --- a/aesjni/src/main/jni/sodium_wrap.c +++ /dev/null @@ -1,1512 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.2 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - - -#ifndef SWIGJAVA -#define SWIGJAVA -#endif - - -/* ----------------------------------------------------------------------------- - * This section contains generic SWIG labels for method/variable - * declarations/attributes, and other compiler dependent labels. - * ----------------------------------------------------------------------------- */ - -/* template workaround for compilers that cannot correctly implement the C++ standard */ -#ifndef SWIGTEMPLATEDISAMBIGUATOR -# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) -# define SWIGTEMPLATEDISAMBIGUATOR template -# elif defined(__HP_aCC) -/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ -/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ -# define SWIGTEMPLATEDISAMBIGUATOR template -# else -# define SWIGTEMPLATEDISAMBIGUATOR -# endif -#endif - -/* inline attribute */ -#ifndef SWIGINLINE -# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) -# define SWIGINLINE inline -# else -# define SWIGINLINE -# endif -#endif - -/* attribute recognised by some compilers to avoid 'unused' warnings */ -#ifndef SWIGUNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define SWIGUNUSED __attribute__ ((__unused__)) -# else -# define SWIGUNUSED -# endif -# elif defined(__ICC) -# define SWIGUNUSED __attribute__ ((__unused__)) -# else -# define SWIGUNUSED -# endif -#endif - -#ifndef SWIG_MSC_UNSUPPRESS_4505 -# if defined(_MSC_VER) -# pragma warning(disable : 4505) /* unreferenced local function has been removed */ -# endif -#endif - -#ifndef SWIGUNUSEDPARM -# ifdef __cplusplus -# define SWIGUNUSEDPARM(p) -# else -# define SWIGUNUSEDPARM(p) p SWIGUNUSED -# endif -#endif - -/* internal SWIG method */ -#ifndef SWIGINTERN -# define SWIGINTERN static SWIGUNUSED -#endif - -/* internal inline SWIG method */ -#ifndef SWIGINTERNINLINE -# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE -#endif - -/* exporting methods */ -#if defined(__GNUC__) -# if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) -# ifndef GCC_HASCLASSVISIBILITY -# define GCC_HASCLASSVISIBILITY -# endif -# endif -#endif - -#ifndef SWIGEXPORT -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# if defined(STATIC_LINKED) -# define SWIGEXPORT -# else -# define SWIGEXPORT __declspec(dllexport) -# endif -# else -# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) -# define SWIGEXPORT __attribute__ ((visibility("default"))) -# else -# define SWIGEXPORT -# endif -# endif -#endif - -/* calling conventions for Windows */ -#ifndef SWIGSTDCALL -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# define SWIGSTDCALL __stdcall -# else -# define SWIGSTDCALL -# endif -#endif - -/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ -#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) -# define _CRT_SECURE_NO_DEPRECATE -#endif - -/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ -#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) -# define _SCL_SECURE_NO_DEPRECATE -#endif - -/* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ -#if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) -# define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 -#endif - -/* Intel's compiler complains if a variable which was never initialised is - * cast to void, which is a common idiom which we use to indicate that we - * are aware a variable isn't used. So we just silence that warning. - * See: https://github.com/swig/swig/issues/192 for more discussion. - */ -#ifdef __INTEL_COMPILER -# pragma warning disable 592 -#endif - - -/* Fix for jlong on some versions of gcc on Windows */ -#if defined(__GNUC__) && !defined(__INTEL_COMPILER) - typedef long long __int64; -#endif - -/* Fix for jlong on 64-bit x86 Solaris */ -#if defined(__x86_64) -# ifdef _LP64 -# undef _LP64 -# endif -#endif - -#include -#include -#include - - -/* Support for throwing Java exceptions */ -typedef enum { - SWIG_JavaOutOfMemoryError = 1, - SWIG_JavaIOException, - SWIG_JavaRuntimeException, - SWIG_JavaIndexOutOfBoundsException, - SWIG_JavaArithmeticException, - SWIG_JavaIllegalArgumentException, - SWIG_JavaNullPointerException, - SWIG_JavaDirectorPureVirtual, - SWIG_JavaUnknownError, - SWIG_JavaIllegalStateException, -} SWIG_JavaExceptionCodes; - -typedef struct { - SWIG_JavaExceptionCodes code; - const char *java_exception; -} SWIG_JavaExceptions_t; - - -static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) { - jclass excep; - static const SWIG_JavaExceptions_t java_exceptions[] = { - { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" }, - { SWIG_JavaIOException, "java/io/IOException" }, - { SWIG_JavaRuntimeException, "java/lang/RuntimeException" }, - { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" }, - { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" }, - { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" }, - { SWIG_JavaNullPointerException, "java/lang/NullPointerException" }, - { SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" }, - { SWIG_JavaUnknownError, "java/lang/UnknownError" }, - { SWIG_JavaIllegalStateException, "java/lang/IllegalStateException" }, - { (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" } - }; - const SWIG_JavaExceptions_t *except_ptr = java_exceptions; - - while (except_ptr->code != code && except_ptr->code) - except_ptr++; - - (*jenv)->ExceptionClear(jenv); - excep = (*jenv)->FindClass(jenv, except_ptr->java_exception); - if (excep) - (*jenv)->ThrowNew(jenv, excep, msg); -} - - -/* Contract support */ - -#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else - - -#include "sodium.h" - - -#ifdef __cplusplus -extern "C" { -#endif - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_sodium_1init(JNIEnv *jenv, jclass jcls) { - jint jresult = 0 ; - int result; - - (void)jenv; - (void)jcls; - result = (int)sodium_init(); - jresult = (jint)result; - return jresult; -} - - -SWIGEXPORT jstring JNICALL Java_com_androidyuan_aesjni_SodiumJNI_sodium_1version_1string(JNIEnv *jenv, jclass jcls) { - jstring jresult = 0 ; - char *result = 0 ; - - (void)jenv; - (void)jcls; - result = (char *)sodium_version_string(); - if (result) jresult = (*jenv)->NewStringUTF(jenv, (const char *)result); - return jresult; -} - - -SWIGEXPORT void JNICALL Java_com_androidyuan_aesjni_SodiumJNI_randombytes_1buf(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jint jarg2) { - void *arg1 = (void *) (void *)0 ; - size_t arg2 ; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - arg2 = (size_t)jarg2; - randombytes_buf(arg1,arg2); - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_randombytes_1random(JNIEnv *jenv, jclass jcls) { - jint jresult = 0 ; - uint32_t result; - - (void)jenv; - (void)jcls; - result = randombytes_random(); - jresult = (jint)result; - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_randombytes_1uniform(JNIEnv *jenv, jclass jcls, jint jarg1) { - jint jresult = 0 ; - uint32_t arg1 ; - uint32_t result; - - (void)jenv; - (void)jcls; - arg1 = (uint32_t)jarg1; - result = randombytes_uniform(arg1); - jresult = (jint)result; - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1sign_1keypair(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - result = (int)crypto_sign_keypair(arg1,arg2); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1sign_1seed_1keypair(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jbyteArray jarg3) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned char *arg3 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - result = (int)crypto_sign_seed_keypair(arg1,arg2,(unsigned char const *)arg3); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1sign(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jlong jarg2, jbyteArray jarg3, jlong jarg4, jbyteArray jarg5) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned long long *arg2 = (unsigned long long *) 0 ; - unsigned char *arg3 = (unsigned char *) 0 ; - unsigned long long arg4 ; - unsigned char *arg5 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - arg2 = *(unsigned long long **)&jarg2; - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - arg4 = (unsigned long long)jarg4; - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - result = (int)crypto_sign(arg1,arg2,(unsigned char const *)arg3,arg4,(unsigned char const *)arg5); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1sign_1open(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jlong jarg2, jbyteArray jarg3, jlong jarg4, jbyteArray jarg5) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned long long *arg2 = (unsigned long long *) 0 ; - unsigned char *arg3 = (unsigned char *) 0 ; - unsigned long long arg4 ; - unsigned char *arg5 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - arg2 = *(unsigned long long **)&jarg2; - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - arg4 = (unsigned long long)jarg4; - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - result = (int)crypto_sign_open(arg1,arg2,(unsigned char const *)arg3,arg4,(unsigned char const *)arg5); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1sign_1detached(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jlong jarg2, jbyteArray jarg3, jlong jarg4, jbyteArray jarg5) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned long long *arg2 = (unsigned long long *) 0 ; - unsigned char *arg3 = (unsigned char *) 0 ; - unsigned long long arg4 ; - unsigned char *arg5 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - arg2 = *(unsigned long long **)&jarg2; - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - arg4 = (unsigned long long)jarg4; - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - result = (int)crypto_sign_detached(arg1,arg2,(unsigned char const *)arg3,arg4,(unsigned char const *)arg5); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1sign_1ed25519_1sk_1to_1curve25519(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - result = (int)crypto_sign_ed25519_sk_to_curve25519(arg1,(unsigned char const *)arg2); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1sign_1ed25519_1pk_1to_1curve25519(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - result = (int)crypto_sign_ed25519_pk_to_curve25519(arg1,(unsigned char const *)arg2); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1sign_1verify_1detached(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jlong jarg3, jbyteArray jarg4) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned long long arg3 ; - unsigned char *arg4 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - arg3 = (unsigned long long)jarg3; - { - arg4 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg4, 0); - } - result = (int)crypto_sign_verify_detached((unsigned char const *)arg1,(unsigned char const *)arg2,arg3,(unsigned char const *)arg4); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg4, (jbyte *) arg4, 0); - } - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1sign_1ed25519_1sk_1to_1seed(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - result = (int)crypto_sign_ed25519_sk_to_seed(arg1,(unsigned char const *)arg2); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1sign_1ed25519_1sk_1to_1pk(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - result = (int)crypto_sign_ed25519_sk_to_pk(arg1,(unsigned char const *)arg2); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1box_1seed_1keypair(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jbyteArray jarg3) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned char *arg3 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - result = (int)crypto_box_seed_keypair(arg1,arg2,(unsigned char const *)arg3); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1box_1keypair(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - result = (int)crypto_box_keypair(arg1,arg2); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1box_1easy(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jlong jarg3, jbyteArray jarg4, jbyteArray jarg5, jbyteArray jarg6) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned long long arg3 ; - unsigned char *arg4 = (unsigned char *) 0 ; - unsigned char *arg5 = (unsigned char *) 0 ; - unsigned char *arg6 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - arg3 = (unsigned long long)jarg3; - { - arg4 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg4, 0); - } - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - { - arg6 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg6, 0); - } - result = (int)crypto_box_easy(arg1,(unsigned char const *)arg2,arg3,(unsigned char const *)arg4,(unsigned char const *)arg5,(unsigned char const *)arg6); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg4, (jbyte *) arg4, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg6, (jbyte *) arg6, 0); - } - - - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1box_1open_1easy(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jlong jarg3, jbyteArray jarg4, jbyteArray jarg5, jbyteArray jarg6) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned long long arg3 ; - unsigned char *arg4 = (unsigned char *) 0 ; - unsigned char *arg5 = (unsigned char *) 0 ; - unsigned char *arg6 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - arg3 = (unsigned long long)jarg3; - { - arg4 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg4, 0); - } - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - { - arg6 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg6, 0); - } - result = (int)crypto_box_open_easy(arg1,(unsigned char const *)arg2,arg3,(unsigned char const *)arg4,(unsigned char const *)arg5,(unsigned char const *)arg6); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg4, (jbyte *) arg4, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg6, (jbyte *) arg6, 0); - } - - - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1box_1detached(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jbyteArray jarg3, jlong jarg4, jbyteArray jarg5, jbyteArray jarg6, jbyteArray jarg7) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned char *arg3 = (unsigned char *) 0 ; - unsigned long long arg4 ; - unsigned char *arg5 = (unsigned char *) 0 ; - unsigned char *arg6 = (unsigned char *) 0 ; - unsigned char *arg7 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - arg4 = (unsigned long long)jarg4; - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - { - arg6 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg6, 0); - } - { - arg7 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg7, 0); - } - result = (int)crypto_box_detached(arg1,arg2,(unsigned char const *)arg3,arg4,(unsigned char const *)arg5,(unsigned char const *)arg6,(unsigned char const *)arg7); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg6, (jbyte *) arg6, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg7, (jbyte *) arg7, 0); - } - - - - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1box_1open_1detached(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jbyteArray jarg3, jlong jarg4, jbyteArray jarg5, jbyteArray jarg6, jbyteArray jarg7) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned char *arg3 = (unsigned char *) 0 ; - unsigned long long arg4 ; - unsigned char *arg5 = (unsigned char *) 0 ; - unsigned char *arg6 = (unsigned char *) 0 ; - unsigned char *arg7 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - arg4 = (unsigned long long)jarg4; - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - { - arg6 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg6, 0); - } - { - arg7 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg7, 0); - } - result = (int)crypto_box_open_detached(arg1,(unsigned char const *)arg2,(unsigned char const *)arg3,arg4,(unsigned char const *)arg5,(unsigned char const *)arg6,(unsigned char const *)arg7); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg6, (jbyte *) arg6, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg7, (jbyte *) arg7, 0); - } - - - - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1secretbox_1easy(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jlong jarg3, jbyteArray jarg4, jbyteArray jarg5) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned long long arg3 ; - unsigned char *arg4 = (unsigned char *) 0 ; - unsigned char *arg5 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - arg3 = (unsigned long long)jarg3; - { - arg4 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg4, 0); - } - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - result = (int)crypto_secretbox_easy(arg1,(unsigned char const *)arg2,arg3,(unsigned char const *)arg4,(unsigned char const *)arg5); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg4, (jbyte *) arg4, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1secretbox_1open_1easy(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jlong jarg3, jbyteArray jarg4, jbyteArray jarg5) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned long long arg3 ; - unsigned char *arg4 = (unsigned char *) 0 ; - unsigned char *arg5 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - arg3 = (unsigned long long)jarg3; - { - arg4 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg4, 0); - } - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - result = (int)crypto_secretbox_open_easy(arg1,(unsigned char const *)arg2,arg3,(unsigned char const *)arg4,(unsigned char const *)arg5); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg4, (jbyte *) arg4, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1secretbox_1detached(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jbyteArray jarg3, jlong jarg4, jbyteArray jarg5, jbyteArray jarg6) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned char *arg3 = (unsigned char *) 0 ; - unsigned long long arg4 ; - unsigned char *arg5 = (unsigned char *) 0 ; - unsigned char *arg6 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - arg4 = (unsigned long long)jarg4; - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - { - arg6 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg6, 0); - } - result = (int)crypto_secretbox_detached(arg1,arg2,(unsigned char const *)arg3,arg4,(unsigned char const *)arg5,(unsigned char const *)arg6); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg6, (jbyte *) arg6, 0); - } - - - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1secretbox_1open_1detached(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jbyteArray jarg3, jlong jarg4, jbyteArray jarg5, jbyteArray jarg6) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned char *arg3 = (unsigned char *) 0 ; - unsigned long long arg4 ; - unsigned char *arg5 = (unsigned char *) 0 ; - unsigned char *arg6 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - arg4 = (unsigned long long)jarg4; - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - { - arg6 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg6, 0); - } - result = (int)crypto_secretbox_open_detached(arg1,(unsigned char const *)arg2,(unsigned char const *)arg3,arg4,(unsigned char const *)arg5,(unsigned char const *)arg6); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg6, (jbyte *) arg6, 0); - } - - - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1auth(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jlong jarg3, jbyteArray jarg4) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned long long arg3 ; - unsigned char *arg4 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - arg3 = (unsigned long long)jarg3; - { - arg4 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg4, 0); - } - result = (int)crypto_auth(arg1,(unsigned char const *)arg2,arg3,(unsigned char const *)arg4); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg4, (jbyte *) arg4, 0); - } - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1auth_1verify(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jlong jarg3, jbyteArray jarg4) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned long long arg3 ; - unsigned char *arg4 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - arg3 = (unsigned long long)jarg3; - { - arg4 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg4, 0); - } - result = (int)crypto_auth_verify((unsigned char const *)arg1,(unsigned char const *)arg2,arg3,(unsigned char const *)arg4); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg4, (jbyte *) arg4, 0); - } - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1aead_1chacha20poly1305_1encrypt(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jlong jarg2, jbyteArray jarg3, jlong jarg4, jbyteArray jarg5, jlong jarg6, jbyteArray jarg7, jbyteArray jarg8, jbyteArray jarg9) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned long long *arg2 = (unsigned long long *) 0 ; - unsigned char *arg3 = (unsigned char *) 0 ; - unsigned long long arg4 ; - unsigned char *arg5 = (unsigned char *) 0 ; - unsigned long long arg6 ; - unsigned char *arg7 = (unsigned char *) 0 ; - unsigned char *arg8 = (unsigned char *) 0 ; - unsigned char *arg9 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - arg2 = *(unsigned long long **)&jarg2; - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - arg4 = (unsigned long long)jarg4; - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - arg6 = (unsigned long long)jarg6; - { - arg7 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg7, 0); - } - { - arg8 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg8, 0); - } - { - arg9 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg9, 0); - } - result = (int)crypto_aead_chacha20poly1305_encrypt(arg1,arg2,(unsigned char const *)arg3,arg4,(unsigned char const *)arg5,arg6,(unsigned char const *)arg7,(unsigned char const *)arg8,(unsigned char const *)arg9); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg7, (jbyte *) arg7, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg8, (jbyte *) arg8, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg9, (jbyte *) arg9, 0); - } - - - - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1aead_1chacha20poly1305_1decrypt(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jlong jarg2, jbyteArray jarg3, jbyteArray jarg4, jlong jarg5, jbyteArray jarg6, jlong jarg7, jbyteArray jarg8, jbyteArray jarg9) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned long long *arg2 = (unsigned long long *) 0 ; - unsigned char *arg3 = (unsigned char *) 0 ; - unsigned char *arg4 = (unsigned char *) 0 ; - unsigned long long arg5 ; - unsigned char *arg6 = (unsigned char *) 0 ; - unsigned long long arg7 ; - unsigned char *arg8 = (unsigned char *) 0 ; - unsigned char *arg9 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - arg2 = *(unsigned long long **)&jarg2; - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - { - arg4 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg4, 0); - } - arg5 = (unsigned long long)jarg5; - { - arg6 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg6, 0); - } - arg7 = (unsigned long long)jarg7; - { - arg8 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg8, 0); - } - { - arg9 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg9, 0); - } - result = (int)crypto_aead_chacha20poly1305_decrypt(arg1,arg2,arg3,(unsigned char const *)arg4,arg5,(unsigned char const *)arg6,arg7,(unsigned char const *)arg8,(unsigned char const *)arg9); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg4, (jbyte *) arg4, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg6, (jbyte *) arg6, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg8, (jbyte *) arg8, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg9, (jbyte *) arg9, 0); - } - - - - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1pwhash_1scryptsalsa208sha256(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jlong jarg2, jstring jarg3, jlong jarg4, jbyteArray jarg5, jlong jarg6, jint jarg7) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) (unsigned char *)0 ; - unsigned long long arg2 ; - char *arg3 = (char *) (char *)0 ; - unsigned long long arg4 ; - unsigned char *arg5 = (unsigned char *) (unsigned char *)0 ; - unsigned long long arg6 ; - size_t arg7 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - arg2 = (unsigned long long)jarg2; - arg3 = 0; - if (jarg3) { - arg3 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg3, 0); - if (!arg3) return 0; - } - arg4 = (unsigned long long)jarg4; - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - arg6 = (unsigned long long)jarg6; - arg7 = (size_t)jarg7; - result = (int)crypto_pwhash_scryptsalsa208sha256(arg1,arg2,(char const *)arg3,arg4,(unsigned char const *)arg5,arg6,arg7); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - - if (arg3) (*jenv)->ReleaseStringUTFChars(jenv, jarg3, (const char *)arg3); - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1pwhash_1scryptsalsa208sha256_1str(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jstring jarg2, jlong jarg3, jlong jarg4, jint jarg5) { - jint jresult = 0 ; - char *arg1 ; - char *arg2 = (char *) (char *)0 ; - unsigned long long arg3 ; - unsigned long long arg4 ; - size_t arg5 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - arg2 = 0; - if (jarg2) { - arg2 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg2, 0); - if (!arg2) return 0; - } - arg3 = (unsigned long long)jarg3; - arg4 = (unsigned long long)jarg4; - arg5 = (size_t)jarg5; - result = (int)crypto_pwhash_scryptsalsa208sha256_str(arg1,(char const *)arg2,arg3,arg4,arg5); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - - if (arg2) (*jenv)->ReleaseStringUTFChars(jenv, jarg2, (const char *)arg2); - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1pwhash_1scryptsalsa208sha256_1str_1verify(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jstring jarg2, jlong jarg3) { - jint jresult = 0 ; - char *arg1 ; - char *arg2 = (char *) (char *)0 ; - unsigned long long arg3 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - arg2 = 0; - if (jarg2) { - arg2 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg2, 0); - if (!arg2) return 0; - } - arg3 = (unsigned long long)jarg3; - result = (int)crypto_pwhash_scryptsalsa208sha256_str_verify((char const (*))arg1,(char const *)arg2,arg3); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - - if (arg2) (*jenv)->ReleaseStringUTFChars(jenv, jarg2, (const char *)arg2); - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1shorthash(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jbyteArray jarg2, jlong jarg3, jbyteArray jarg4) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - unsigned char *arg2 = (unsigned char *) 0 ; - unsigned long long arg3 ; - unsigned char *arg4 = (unsigned char *) 0 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - { - arg2 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg2, 0); - } - arg3 = (unsigned long long)jarg3; - { - arg4 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg4, 0); - } - result = (int)crypto_shorthash(arg1,(unsigned char const *)arg2,arg3,(unsigned char const *)arg4); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg2, (jbyte *) arg2, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg4, (jbyte *) arg4, 0); - } - - - - return jresult; -} - - -SWIGEXPORT jint JNICALL Java_com_androidyuan_aesjni_SodiumJNI_crypto_1generichash(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jint jarg2, jbyteArray jarg3, jlong jarg4, jbyteArray jarg5, jint jarg6) { - jint jresult = 0 ; - unsigned char *arg1 = (unsigned char *) 0 ; - size_t arg2 ; - unsigned char *arg3 = (unsigned char *) 0 ; - unsigned long long arg4 ; - unsigned char *arg5 = (unsigned char *) 0 ; - size_t arg6 ; - int result; - - (void)jenv; - (void)jcls; - { - arg1 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg1, 0); - } - arg2 = (size_t)jarg2; - { - arg3 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg3, 0); - } - arg4 = (unsigned long long)jarg4; - { - arg5 = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarg5, 0); - } - arg6 = (size_t)jarg6; - result = (int)crypto_generichash(arg1,arg2,(unsigned char const *)arg3,arg4,(unsigned char const *)arg5,arg6); - jresult = (jint)result; - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg1, (jbyte *) arg1, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg3, (jbyte *) arg3, 0); - } - { - (*jenv)->ReleaseByteArrayElements(jenv, jarg5, (jbyte *) arg5, 0); - } - - - - return jresult; -} - - -#ifdef __cplusplus -} -#endif - diff --git a/aesjni/src/main/jni/swig_gen.sh b/aesjni/src/main/jni/swig_gen.sh deleted file mode 100755 index f158536..0000000 --- a/aesjni/src/main/jni/swig_gen.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh -# @Author: bruce - -command_exists() { - # check if command exists and fail otherwise - command -v "$1" >/dev/null 2>&1 - if [[ $? -ne 0 ]]; then #not found. - return 0 - else - return 1 - fi -} - -install_app_on_debian() { - echo "Debian try to install $1." - sudo apt update - sudo apt install $1 -} -install_app_on_mac() { - echo "This computer try to install $1." - brew install $1 -} - - -install_app() { - echo "try to install $1." - if [ -f /etc/debian_version ]; then - install_app_on_debian $1 - elif [[ "$OSTYPE" == "linux-gnu"* ]]; then - install_app_on_debian $1 - elif [[ "$OSTYPE" == "darwin"* ]]; then - install_app_on_mac $1 - else - echo "can't run on this system." - exit 1 - fi -} - - - - -try_install_app() { - command_exists $1 - is_app_installed=$? - if [ "$is_app_installed" -eq "0" ]; then - install_app $1 - command_exists $1 - is_app_installed=$? - if [ "$is_app_installed" -eq "0" ]; then - printf 'Error: %s has not been installed.\n' $1 - exit 1 - fi - fi -} - -# install swig if it has not been intalled. -try_install_app swig -# start generating to get c file and java class. -swig -java -package com.androidyuan.aesjni -outdir ../java/com/androidyuan/aesjni/ sodium.i \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 05f174c..8b1f8ec 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,9 @@ android { } signingConfigs { + //you can regenerate it. release { - storeFile file("../keystore/androidyuan.keystore") //请看目录 + storeFile file("../keystore/androidyuan.keystore") storePassword "weizongwei" keyAlias "client1" keyPassword "weizongwei" @@ -36,11 +37,18 @@ android { dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + implementation fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.0.1' - compile project(':aesjni') - testCompile 'junit:junit:4.12' + implementation 'com.android.support:appcompat-v7:25.0.1' + implementation project(':aesjni') + + + // Required for local unit tests (JUnit 4 framework) + testImplementation 'junit:junit:4.12' + + // Required for instrumented tests + testImplementation 'com.android.support:support-annotations:24.0.0' + testImplementation 'com.android.support.test:runner:0.5' } diff --git a/app/src/main/java/com/androidyuan/aesjniencrypt/MainActivity.java b/app/src/main/java/com/androidyuan/aesjniencrypt/MainActivity.java index 3c8656b..2556820 100644 --- a/app/src/main/java/com/androidyuan/aesjniencrypt/MainActivity.java +++ b/app/src/main/java/com/androidyuan/aesjniencrypt/MainActivity.java @@ -5,7 +5,7 @@ import android.util.Log; import android.widget.Toast; -import com.androidyuan.aesjni.AESEncrypt; +import com.androidyuan.aesjni.EncryptEntry; public class MainActivity extends AppCompatActivity { @@ -19,12 +19,11 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); //下面的密文对应的原文:123abcABC&*(@#@#@)+_/中文测试 - final String code = AESEncrypt.encode(this, str); + final String code = EncryptEntry.encode(this, str); Log.i("code", code + ""); - final String decode = AESEncrypt.decode(this, encodeStr); + final String decode = EncryptEntry.decode(this, encodeStr); Log.i("decode", decode + ""); - } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index c123a06..980be40 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -15,6 +15,6 @@ diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml new file mode 100644 index 0000000..22ecf14 --- /dev/null +++ b/app/src/main/res/values-zh/strings.xml @@ -0,0 +1,4 @@ + + AESJniEncrypt + 兄弟,这里是空的,加解密已经完成请看logcat! + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4a2bb0d..5085635 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,4 @@ AESJniEncrypt + There is nothing. Encryption and decryption has executed,Pls look at logcat. diff --git a/gradle.properties b/gradle.properties index 8f62aea..79af975 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,4 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -android.useDeprecatedNdk = true \ No newline at end of file +#android.useDeprecatedNdk = true \ No newline at end of file