Resource Encryption encrypts the resources packaged in your Android app or library, so attackers can't easily copy or alter them. During the build, PreEmptive Protection™ DashO™ encrypts your resources with AES, a symmetric encryption algorithm, and injects code that decrypts them in the running app. DashO encrypts both assets and raw resources.
This article explains how Resource Encryption works. To configure it, see Configuring Resource Encryption.
Where Resource Encryption Is Available
| Configuration | Supported |
| Android Mode with the Gradle integration through the DashO Gradle Plugin for Android | Yes |
| APK post-processing | No |
| Gradle integration through the DashO Gradle Plugin for Java | No |
How it Works
- The DashO Gradle Plugin for Android generates a secret key. It passes the key to DashO in an environment variable, so the key doesn't appear in log files or process lists.
- The
encryptResourcestask encrypts the selected resources for each build variant where DashO is enabled. For each variant, DashO encrypts only the resources that are part of that variant. Your original resource files don't change. - When DashO protects your code, it injects code that decrypts the resources when your app accesses them. It also adds the
Wrapper$Secretsclass, which contains the secret key.
Supported APIs and Behavior
DashO encrypts assets and raw resources your app accesses through InputStream. It wraps the InputStream objects that access encrypted resources with an InputStream implementation that decrypts the data. DashO automatically injects decryption code for streams these methods produce:
AssetManager.open(String)AssetManager.open(String, int)Resources.openRawResource(int)Resources.openRawResource(int, TypedValue)
Some libraries the Android Gradle Plugin includes as inputs to DashO call these methods. These include compatibility libraries with classes under the android or androidx packages, but not anything in android.jar. Resource Encryption supports any API in these libraries that delegates resource reading to these methods. To see exactly which calls DashO wraps, review the DashO build output with debug enabled.
The result depends on whether the resource is encrypted and whether the call that reads it is wrapped:
| Resource | Call is wrapped | Call isn't wrapped |
| Encrypted | The app reads the decrypted data. | The result is undefined. Formats with their own consistency checks likely throw a format exception. Other formats may cause undefined behavior. |
| Not encrypted | The data passes through unmodified. | The app reads the data normally. |
What You Configure
- Assets and raw resources independently. Enable or disable protection for each type separately.
- Include and exclude rules for assets and raw resources, to choose which files DashO encrypts.
You can't control where DashO injects decryption code, except with Global Processing Exclusions. These stop DashO from making any changes to the selected classes.
Library (AAR) Projects
Resource Encryption supports library (AAR) projects, but problems may occur if an app protects the library again with DashO's Resource Encryption.
- When you build the library, configure the decryption classes to be renamed by R8.
- When you include the library in an app, use the
excludeFromProtectionfeature to keep DashO from processing the library again. - Apps can't access encrypted resources in an AAR directly. If your library provides resources to apps, exclude those resources from encryption, or have apps access them through APIs your library provides.
Performance
Decryption is processor-bound, so expect some decrease in runtime performance when Resource Encryption is enabled. Test the performance of your app or library with and without Resource Encryption. If performance suffers, exclude less sensitive files from encryption.
Limitations and Troubleshooting
| Limitation or issue | Details |
| Resource Encryption isn't available. | It's only available in Android Mode with the DashO Gradle Plugin for Android. APK post-processing and the DashO Gradle Plugin for Java aren't supported. |
| The app throws a format exception or behaves unpredictably when reading a resource. | The resource is encrypted, but the call that reads it isn't wrapped. Exclude the resource. |
| An app can't read resources from your protected library. | Apps can't access encrypted AAR resources directly. |
| Problems when an app protects your library again. | Use excludeFromProtection in the app, and have R8 rename the decryption classes when you build the library. |
| You need to keep decryption code out of specific classes. | Use Global Processing Exclusions. Note that they stop all DashO changes to those classes. |
| The app is slower. | Decryption is processor-bound. Exclude less sensitive files. |