How xuningjack/apikeylib works
1. Repository purpose
- This is an Android project centered on request-signature generation for network calls.
- The core problem it solves is: take request parameters, normalize them, and produce a sign/authorization string using sorting + concatenation + MD5, with part of the logic implemented in native C++.
2. Top-level structure
- The repo has two main runtime modules:
- apikeylib: reusable library containing the signing logic.
- app: sample Android application that demonstrates how to call the library.
- Supporting files at the root are standard Gradle/Android build infrastructure.
3. Core library boundary: apikeylib
- apikeylib is the architectural center of the repo.
- Its public Java entry point is com.jack.apikeylib.SignHelper.
- This module also contains the native implementation under src/main/cpp, indicating the library is designed to keep at least part of the signing algorithm in JNI/native code.
4. Public API surface
- The README exposes two main signing flows:
- Authorization/sign generation from request body: sort map-style parameters by key, concatenate values, then append user_token, appkey, and timestamp, and MD5 the result.
- MD5-based native encryption flow: compute MD5-based signing by passing a sign string through a native method.
- From an architecture standpoint, SignHelper is the API boundary that consumers should use; the rest is implementation detail.
5. Native implementation layer
- The cpp subtree contains the low-level cryptographic and string utilities:
- api_helper.cpp/.h: likely the JNI bridge and/or native orchestration layer.
- encrypt/md5.cpp/.h: MD5 implementation.
- encrypt/base64.h, encrypt/urlEncode.h: helper utilities for encoding/decoding.
- string_helper.h: string manipulation helpers.
- This layer is where the signing algorithm’s sensitive or performance-critical parts live.
6. Data flow for signing
- Expected flow is:
- The app or another client constructs request parameters.
- Parameters are normalized by key ordering and value concatenation.
- Additional fields such as user_token, appkey, and timestamp are appended depending on the signing mode.
- The final string is hashed with MD5.
- The result is returned to Java and then to the caller for use as an authorization/sign header or request parameter.
- The repo is about deterministic transformation, not persistence or networking.
7. Android sample app
- The app module is a demonstration client, not the core product.
- MainActivity and EncryptUtil suggest the app provides a UI or simple wrapper to test or showcase the signing functions.
- activity_main.xml and the Android resources support this sample UI, likely to let developers verify generated signatures.
8. Build and integration architecture
- The library uses Gradle plus CMake, showing a mixed Java + native build.
- build.gradle, settings.gradle, and gradle/wrapper define the Android build pipeline.
- apikeylib/CMakeLists.txt and api_helper.cpp indicate the native code is compiled as part of the Android library and packaged into the AAR/apk.
9. Packaging and runtime dependencies
- The library is self-contained; there are no visible backend services, databases, or third-party runtime systems in the tree.
- The only meaningful runtime boundary is between:
- Java/Kotlin Android code in the app/library
- JNI native C++ code inside apikeylib
- That boundary matters because the signing implementation is split across managed and native code.
10. Security/obfuscation implication
- Keeping part of the sign logic in native code suggests an intent to make the algorithm less exposed than a pure-Java implementation.
- proguard-rules.pro in both modules indicates the project is prepared for Android code shrinking/obfuscation.
11. How to draw the architecture
- A useful diagram would show:
- App UI / caller
→ EncryptUtil / SignHelper Java API
→ JNI bridge (api_helper)
→ native crypto utilities (md5, encoding helpers)
→ signature output returned to Java
- The app module should be shown as a consumer of the apikeylib module, not as part of the signing engine itself.
12. What is not present
- There is no evidence of server components, message queues, persistence, analytics, or external APIs.
- This repo is primarily a client-side Android signing library with a demo app rather than a full system.
Main entry points: api_helper.cpp JNI bridge · EncryptUtil.java EncryptUtil · MainActivity.java MainActivity · SignHelper.java SignHelper
Components 14
Build
Gradle and native build setup
- Gradle build · Top-level Gradle and wrapper configuration
build.gradle - Settings · Project module registration
settings.gradle
apikeylib
Reusable signature library
- CMake · Native build definition for the library
apikeylib/CMakeLists.txt - Lib manifest · Library component declaration
apikeylib/src/main/AndroidManifest.xml - SignHelper · Public signing entry point for consumers
apikeylib/src/main/java/com/jack/apikeylib/SignHelper.java - JNI bridge · Native orchestration and Java-native boundary
apikeylib/src/main/cpp/api_helper.cpp - MD5 core · Native MD5 hashing implementation
apikeylib/src/main/cpp/encrypt/md5.cpp - String utils · String normalization and helper routines
apikeylib/src/main/cpp/string_helper.h - Base64 · Native base64 helper header
apikeylib/src/main/cpp/encrypt/base64.h - URL encode · Native URL encoding helper header
apikeylib/src/main/cpp/encrypt/urlEncode.h
app
Sample Android client
- App manifest · Sample app declaration
app/src/main/AndroidManifest.xml - MainActivity · Demo screen that exercises signing
app/src/main/java/cn/jack/apikeynativelib/MainActivity.java - EncryptUtil · App-side helper for invoking the library
app/src/main/java/cn/jack/apikeynativelib/EncryptUtil.java - UI layout · Sample UI layout for signature testing
app/src/main/res/layout/activity_main.xml
Connections 14
- Settings → Gradle build: includes · Registers modules in the Gradle build
- Gradle build → CMake: drives · Top-level build triggers native compilation
- CMake → JNI bridge: compiles · Builds the JNI/native entry point
- JNI bridge → MD5 core: uses · Delegates hashing to native MD5 code
- JNI bridge → String utils: uses · Relies on string normalization helpers
- JNI bridge → Base64: uses · Uses encoding utilities in native code
- JNI bridge → URL encode: uses · Uses URL encoding utilities in native code
- SignHelper → JNI bridge: calls native · Java API delegates sensitive work to JNI
- MainActivity → EncryptUtil: uses · UI invokes app-side wrapper methods
- EncryptUtil → SignHelper: calls · App wrapper calls the reusable library API
- MainActivity → UI layout: renders · Activity is backed by the sample layout
- App manifest → MainActivity: declares · Application entry component
- Lib manifest → SignHelper: exposes · Library package exports the public API surface
- EncryptUtil → JNI bridge: tests · Sample wrapper may exercise native signing behavior