Giter Site home page Giter Site logo

jnitool's Introduction

JNITool

NDK实现的工具库,支持AES的ECB和CBC加解密(支持emoji),MD5加盐

AES基于tiny-AES128-C扩展,根据key长度自动选择AES128、AES192、AES256

默认采用PKCS7Padding填充(和PKCS5Padding一样),加密后进行一次Base64

应用包名和签名的hash code放在native层,使用前会进行签名检验,防二次打包

JNITool.java :

    public static native String pwdMD5(String str);
    public static String encrypt(String str);
    public static String decrypt(String str);

aes.c :

    char *AES_ECB_PKCS7_Encrypt(const char *in, const uint8_t *key);
    char *AES_ECB_PKCS7_Decrypt(const char *in, const uint8_t *key);
    char *AES_CBC_PKCS7_Encrypt(const char *in, const uint8_t *key, const uint8_t *iv);
    char *AES_CBC_PKCS7_Decrypt(const char *in, const uint8_t *key, const uint8_t *iv);

使用前记得修改jni_tool.cpp的以下内容:

    static const char *app_packageName = "com.wtuadn.demo";
    static const int app_signature_hash_code = -827662039;
    static const uint8_t AES_KEY[] = "xS544RXNm0P4JVLHIEsTqJNzDbZhiLjr";
    static const uint8_t AES_IV[] = "KXTUDEdBs9zGlvy7";
    static const string PWD_MD5_KEY = "4J9lKuR2c8OuDPBAniEy5USFQdSM0An4";

app_signature_hash_code获取方法见demo

Tips

如果只用到ECB或者CBC算法,可以把aes.h头文件里没用到的定义注释掉,减小生成的so文件体积

    #ifndef CBC
      #define CBC 1
    #endif

    #ifndef ECB
      #define ECB 1
    #endif

鸣谢

tiny-AES128-CAESJniEncryptMD5

jnitool's People

Contributors

wtuadn avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.