You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Please remember that no client-side security measures are invincible. As a rule of thumb, **storing secrets in a mobile app is not considered best practice**. However, when there's no other option, this method is our best recommendation for concealing them.
13
13
14
-
# 1) Getting started
14
+
# 1) Getting Started
15
15
16
16
To use the Secrets Vault Plugin in your Android project, follow these steps:
17
17
@@ -37,7 +37,7 @@ plugins {
37
37
}
38
38
```
39
39
40
-
# 2) Keep secrets in your project
40
+
# 2) Keep Secrets in Your Project
41
41
42
42
To keep secrets in your project, you can add them to a JSON file located in the root folder of the module where you've applied the plugin.
43
43
Follow the format below:
@@ -81,7 +81,7 @@ secretsVault {
81
81
- The `projectName` parameter is optional and uses the module's name where the plugin is applied by default. You can specify a different project name if needed.
82
82
- The `version` parameter is optional. If not provided, a default CMake version will be used.
83
83
84
-
# 3) Get your secret key in your app
84
+
# 3) Get Your Secret Key in Your App
85
85
To enable the compilation of C++ files, add these lines in the Module level `build.gradle[.kts]` :
86
86
```gradle
87
87
android {
@@ -96,12 +96,53 @@ android {
96
96
}
97
97
```
98
98
99
+
## Access inside Kotlin
100
+
99
101
Access your secret key by calling :
100
102
```kotlin
101
103
val key =MainSecrets().getYourSecretKeyName()
102
104
```
103
105
104
-
# 4) Flavor-specific secrets (Optional)
106
+
## Access inside Java
107
+
108
+
The names of the methods in the generated files (`MainSecrets.kt` & `Secrets.kt`) are replaced with dummy strings such as `a0` on the `JVM` side for extra security. This makes accessing these methods inside `Java` classes a bit tricky since those names are not "readable" and are dependent on the order in `secrets.json` file.
109
+
110
+
As as solution, a helper/wrapper `Kotlin` class can be created instead of accessing these methods directly inside a `Java` class:
111
+
112
+
`MySecretsHelper.kt`:
113
+
```kotlin
114
+
internalclassMySecretsHelper {
115
+
val secrets =MainSecrets() // Suppose contains "external fun getYourSecretKeyName(): String" with "@JvmName("a0")" annotation.
116
+
val mySecret:String get() = secrets.getYourSecretKeyName()
If you are working on multi-flavor projects and have flavor-specific secrets, you need to pass arguments to CMake in your `build.gradle[.kts]` file. Follow the steps below:
106
147
107
148
```gradle
@@ -207,7 +248,7 @@ android {
207
248
```
208
249
Remember to replace version in -Dversion=flavorName with the appropriate cmakeArgument from your JSON. The flavorName should correspond to the specific product flavor you're building for.
209
250
210
-
# 6) Enhance your secrets security (Optional)
251
+
# 6) Enhance Your Secrets' Security (Optional)
211
252
To enhance the security of your secrets, you can create a custom encoding/decoding algorithm. The secrets will be stored in C++ and further secured by applying your custom encoding algorithm. Additionally, the decoding algorithm will be compiled, making it more challenging for an attacker to reverse-engineer and obtain your keys.
0 commit comments