Objective
The reverse is based on the development of the reverse analysis often use some public cryptographic functions to encrypt the data, through the use of openssl familiarity.
Body
You first have to compile openssl them and copy them to your project directory.
includeis openssl the header file. The lib ones below are compiled so.
Then modify build.gradle the cmake items in:
cppFlagsis the compile option, which abiFilters specifies the compilation abi so, lib corresponding to the directory entry in the directory just before. It's going to be used later.
Increase
jniLibs.srcDirsA directory with a value of so openssl . This means that you can copy these directly when packing.
The finalbuild.gradle
Apply plugin: ' Com.android.application ' Android {compilesdkversion defaultconfig {applicationid ' Com.exam Ple.administrator.oi "Minsdkversion targetsdkversion versioncode 1 Versionname" 1.0 " Testinstrumentationrunner "Android.support.test.runner.AndroidJUnitRunner" Externalnativebuild {CMA ke {cppflags "-std=c++11-frtti-fexceptions" Abifilters ' Armeabi ', ' armeabi-v7a ' }}} buildtypes {release {minifyenabled false proguardfiles Getdefaultprogu Ardfile (' Proguard-android.txt '), ' Proguard-rules.pro '}} sourcesets {main {JNILIBS.SRCDI rs = ["C:\\users\\administrator\\androidstudioprojects\\oi\\app\\openssl_resouce\\lib"]}} ExternalNativeBui LD {cmake {path ' CMakeLists.txt '}}}dependencies {implementation filetree (dir: ' Libs ', Include: [' *.jar ']) IMplementation ' com.android.support:appcompat-v7:26.1.0 ' implementation ' Com.android.support.constraint: constraint-layout:1.0.2 ' testimplementation ' junit:junit:4.12 ' androidtestimplementation ' com.android.support.test : runner:1.0.1 ' androidtestimplementation ' com.android.support.test.espresso:espresso-core:3.0.1 '}
Then modify CMakeLists.txt , where the Chinese annotation is modified.
# For more information on using CMake with Android Studio, read the# Documentation:https://d.android.com/studio/projec ts/add-native-code.html# sets the minimum version of CMake required to build the native library.cmake_minimum_required (VER SION 3.4.1) # Set header file loaded directory Include_directories (c:/users/administrator/androidstudioprojects/oi/app/openssl_resouce/ Include) #动态方式加载add_library (OpenSSL shared imported) add_library (SSL SHARED imported) #引入第三方. So library, according to ${android_abi} Reference to different library set_target_properties (OpenSSL properties Imported_location c:/users/administrator/androidstudioprojects/oi/ app/openssl_resouce/lib/${android_abi}/libcrypto.so) set_target_properties (SSL properties Imported_location C:/ users/administrator/androidstudioprojects/oi/app/openssl_resouce/lib/${android_abi}/libssl.so) # Creates and names A library, sets it as either static# or SHARED, and provides the relative paths to their source code.# you can define Multip Le libraries, and CMake builds them for you.# Gradle automatically packagEs shared libraries with your apk.add_library (# Sets the name of the library. Native-lib # Sets the library as a shared library. SHARED # provides a relative path to your source file (s). Src/main/cpp/native-lib.cpp) # Searches for a specified prebuilt library and stores the path as a# variable. Because CMake includes system libraries in the search path by# default, you have need to specify the name of the public ND K library# you want to add. CMake verifies that the library exists before# completing its build.find_library (# sets the name of the path variable. Log-lib # Specifies the name of the NDK library that's want CMake to locate. LOG) # Specifies libraries CMake should link to your target library. you# can link multiple libraries, such as libraries you define in this# build script, prebuilt third-party libraries, or S Ystem libraries.# Set link Options target_link_libraries (#Specifies the target library. Native-lib OpenSSL SSL # Links the target library to the Log Library # included in the NDK. ${log-lib})
Then you can use it.
Project path
https://gitee.com/hac425/android_openssl/
Android Studio uses OpenSSL