一套面向"用户敏感数据保护"的 Android 库,全 Kotlin / 全 Compose / 零反射 / 零 DI 依赖。
📦 Maven 坐标: com.github.visiongem.android-secure-toolkit:<module>:0.1.0
🔗 GitHub: https://github.com/visiongem/android-secure-toolkit
Android 平台层的安全 API(Keystore、BiometricPrompt、FLAG_SECURE)功能完整但官方文档分散、StackOverflow 答案普遍过时。本库把高安全场景下验证过的写法抽离为 3 个互相独立的小库,开箱即用。
| 模块 | 干什么 | 一句话使用 |
|---|---|---|
:securestore |
用 AndroidKeyStore 把字符串落盘(AES-256-GCM) | SecureStore.encrypt(alias, "secret") |
:biometricvault |
指纹保护任意 AES key,自动失效防换指纹绕过 | BiometricVault.obtainEncryptCipher(ctx, alias) |
:screensecure |
Compose 一行代码加 FLAG_SECURE 防截屏 |
ScreenshotProtector() |
Verified on: OnePlus 9 (LE2113) / OxygenOS / Android 14 Instrumented tests:
:securestore10/10 passing on real AndroidKeyStore
|
Sample 主页(SecureStore + BiometricVault 加解密往返成功)
|
ScreenshotProtector 生效(系统拦截截屏)
|
第二张图是用另一台手机翻拍的——因为
ScreenshotProtector一开,连截屏键都按不动了。系统 toast 中文文案是 OxygenOS 风格(AOSP 标准是英文Can't take screenshot due to security policy)。完整真机验证步骤见 docs/RUNNING_SAMPLE.md。
// 1. 加密一段敏感字符串落盘
val token = SecureStore.encrypt(alias = "user_token", plaintext = rawToken)
prefs.edit().putString("token", token).apply()
// 2. 在敏感页加防截屏(Compose)
@Composable fun MnemonicScreen() {
ScreenshotProtector()
Text("your seed phrase here")
}
// 3. 用指纹保护一个 AES key(典型流程见 sample app)
when (val r = BiometricVault.obtainEncryptCipher(activity, alias = "wallet_key")) {
is VaultResult.Cipher -> BiometricUiHelper.authenticateAndEncrypt(
activity, r.cipher, plaintext = secret,
onSuccess = { encoded -> /* 落盘 */ },
onError = { _, _ -> },
)
VaultResult.KeyInvalidated -> { /* 引导用户重新设置 */ }
VaultResult.Unavailable -> { /* 设备不支持 */ }
is VaultResult.Failure -> { /* 处理异常 */ }
}settings.gradle.kts:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}app/build.gradle.kts(按需选择):
dependencies {
implementation("com.github.visiongem.android-secure-toolkit:securestore:0.1.0")
implementation("com.github.visiongem.android-secure-toolkit:biometricvault:0.1.0")
implementation("com.github.visiongem.android-secure-toolkit:screensecure:0.1.0")
}把
visiongem换成实际用户名。每个模块独立可装,不强制三个一起引。
- 零强依赖:库不引入 Hilt / Koin / RxJava;调用方按需自接 DI。
- 失败即 null:默认 API 不抛异常,避免上层全到处 try-catch。需要详细错误用
xxxOrThrow。 - 不偷偷弱化:
AES-256-GCM、12B IV、128bit GCM tag全部硬编码,不让调用方传弱配置。
- minSdk 24(KeyStore Provider AES 模式可用最低版本)
- BiometricVault 实际生效需 API 28+ 且设备已注册强生物识别
- StrongBox 仅 Pixel 3+ / 三星 S 系列等高端机
Apache 2.0,详见 LICENSE。


