diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..914b8cc
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,14 @@
+version: 2
+updates:
+ - package-ecosystem: gradle
+ directory: /
+ schedule:
+ interval: weekly
+ day: monday
+ open-pull-requests-limit: 5
+ - package-ecosystem: github-actions
+ directory: /
+ schedule:
+ interval: weekly
+ day: monday
+ open-pull-requests-limit: 5
diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml
index 1e477a0..ed17c89 100644
--- a/.github/workflows/android-ci.yml
+++ b/.github/workflows/android-ci.yml
@@ -2,7 +2,7 @@ name: Android Cipher CI
on:
push:
- branches: [main, "upgrade/**"]
+ branches: [main, "release/**", "upgrade/**"]
pull_request:
branches: [main]
workflow_dispatch:
@@ -11,40 +11,82 @@ permissions:
contents: read
concurrency:
- group: android-ci-${{ github.ref }}
+ group: android-ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-test:
- name: Build and unit tests
+ name: Unit tests, lint and release variants
runs-on: ubuntu-latest
steps:
- name: Check out source
- uses: actions/checkout@v4
+ uses: actions/checkout@v7
- name: Set up JDK 17
- uses: actions/setup-java@v4
+ uses: actions/setup-java@v6
with:
distribution: temurin
java-version: "17"
+ - name: Validate Gradle wrapper
+ uses: gradle/actions/wrapper-validation@v6
+
- name: Set up Gradle
- uses: gradle/actions/setup-gradle@v4
+ uses: gradle/actions/setup-gradle@v6
- name: Set up Android SDK
- uses: android-actions/setup-android@v3
+ uses: android-actions/setup-android@v4
with:
packages: platform-tools
- name: Install Android 36 SDK
run: sdkmanager "platforms;android-36" "build-tools;36.0.0"
- - name: Run tests, lint and assemble debug/release APKs
- run: bash gradlew --no-daemon clean testDebugUnitTest lintDebug assembleDebug assembleRelease
+ - name: Run unit tests, lint and assemble installable build variants
+ run: bash gradlew --no-daemon clean testDebugUnitTest lintDebug assembleDebug assembleRelease bundleRelease
- - name: Upload debug and release APKs
- uses: actions/upload-artifact@v4
+ - name: Upload APK and App Bundle build outputs
+ uses: actions/upload-artifact@v7
with:
- name: android-cipher-apks
- path: app/build/outputs/apk/**/*.apk
+ name: android-cipher-2.2.0-builds
+ path: |
+ app/build/outputs/apk/**/*.apk
+ app/build/outputs/bundle/**/*.aab
if-no-files-found: error
+ retention-days: 30
+
+ emulator-smoke-tests:
+ name: Emulator UI tests (API ${{ matrix.api-level }})
+ needs: build-and-test
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ api-level: [26, 36]
+ steps:
+ - name: Check out source
+ uses: actions/checkout@v7
+
+ - name: Set up JDK 17
+ uses: actions/setup-java@v6
+ with:
+ distribution: temurin
+ java-version: "17"
+
+ - name: Set up Gradle
+ uses: gradle/actions/setup-gradle@v6
+
+ - name: Set up Android SDK
+ uses: android-actions/setup-android@v4
+ with:
+ packages: platform-tools
+
+ - name: Run Espresso tests on Android API ${{ matrix.api-level }}
+ uses: ReactiveCircus/android-emulator-runner@v2.38.0
+ with:
+ api-level: ${{ matrix.api-level }}
+ target: default
+ arch: x86_64
+ profile: pixel_2
+ disable-animations: true
+ script: bash gradlew --no-daemon connectedDebugAndroidTest
diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml
new file mode 100644
index 0000000..1f2082b
--- /dev/null
+++ b/.github/workflows/publish-release.yml
@@ -0,0 +1,111 @@
+name: Signed Android release
+
+on:
+ push:
+ branches: [main]
+ paths:
+ - "app/build.gradle"
+ - "app/src/**"
+ - ".github/workflows/publish-release.yml"
+ workflow_dispatch:
+
+permissions:
+ contents: write
+
+concurrency:
+ group: android-cipher-release-${{ github.ref }}
+ cancel-in-progress: false
+
+jobs:
+ publish:
+ name: Build and publish signed APK and App Bundle
+ runs-on: ubuntu-latest
+ steps:
+ - name: Check out source
+ uses: actions/checkout@v7
+
+ - name: Set up JDK 17
+ uses: actions/setup-java@v6
+ with:
+ distribution: temurin
+ java-version: "17"
+
+ - name: Validate Gradle wrapper
+ uses: gradle/actions/wrapper-validation@v6
+
+ - name: Set up Gradle
+ uses: gradle/actions/setup-gradle@v6
+
+ - name: Set up Android SDK
+ uses: android-actions/setup-android@v4
+ with:
+ packages: platform-tools
+
+ - name: Install Android 36 SDK
+ run: sdkmanager "platforms;android-36" "build-tools;36.0.0"
+
+ - name: Check release signing credentials
+ id: signing
+ shell: bash
+ env:
+ ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
+ ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
+ ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
+ ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
+ run: |
+ if [[ -z "$ANDROID_KEYSTORE_BASE64" || -z "$ANDROID_KEYSTORE_PASSWORD" || -z "$ANDROID_KEY_ALIAS" || -z "$ANDROID_KEY_PASSWORD" ]]; then
+ echo "configured=false" >> "$GITHUB_OUTPUT"
+ {
+ echo "## Signed release not published"
+ echo
+ echo "The Android signing secrets are not configured. No unsigned or debug-signed package will be published as a stable release."
+ echo
+ echo "Configure repository Actions secrets: ANDROID_KEYSTORE_BASE64, ANDROID_KEYSTORE_PASSWORD, ANDROID_KEY_ALIAS, and ANDROID_KEY_PASSWORD. Re-run this workflow after configuration."
+ } >> "$GITHUB_STEP_SUMMARY"
+ exit 0
+ fi
+
+ KEYSTORE_PATH="$RUNNER_TEMP/android-cipher-release.jks"
+ printf '%s' "$ANDROID_KEYSTORE_BASE64" | base64 --decode > "$KEYSTORE_PATH"
+ chmod 600 "$KEYSTORE_PATH"
+ echo "ANDROID_KEYSTORE_PATH=$KEYSTORE_PATH" >> "$GITHUB_ENV"
+ echo "configured=true" >> "$GITHUB_OUTPUT"
+
+ - name: Build signed release APK and App Bundle
+ if: steps.signing.outputs.configured == 'true'
+ env:
+ ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
+ ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
+ ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
+ run: bash gradlew --no-daemon clean testDebugUnitTest lintRelease assembleRelease bundleRelease
+
+ - name: Publish GitHub Release
+ if: steps.signing.outputs.configured == 'true'
+ env:
+ GH_TOKEN: ${{ github.token }}
+ shell: bash
+ run: |
+ VERSION_NAME="$(sed -n 's/.*versionName "\([^"]*\)".*/\1/p' app/build.gradle | head -n 1)"
+ TAG="v$VERSION_NAME"
+ if gh release view "$TAG" >/dev/null 2>&1; then
+ echo "Release $TAG already exists; refusing to overwrite published assets."
+ exit 1
+ fi
+ gh release create "$TAG" \
+ app/build/outputs/apk/release/app-release.apk \
+ app/build/outputs/bundle/release/app-release.aab \
+ --title "Android Cipher $VERSION_NAME" \
+ --generate-notes \
+ --target "$GITHUB_SHA" \
+ --latest
+
+ - name: Upload signed build outputs for audit
+ if: steps.signing.outputs.configured == 'true'
+ uses: actions/upload-artifact@v7
+ with:
+ name: android-cipher-signed-release
+ path: |
+ app/build/outputs/apk/release/*.apk
+ app/build/outputs/bundle/release/*.aab
+ if-no-files-found: error
+ retention-days: 90
diff --git a/README.md b/README.md
index 2d827d2..c4790cf 100644
--- a/README.md
+++ b/README.md
@@ -1,94 +1,110 @@
-# Android Cipher 2.1
+# Android Cipher 2.2
-A lightweight, offline-first Android text encryption app built with Java and Material Components.
+A lightweight, offline-first Android text encryption app built with Java and Material 3 Expressive.
-> **Security note:** Android Cipher 2.1 uses password-based AES-256-GCM for new messages. It is a small utility project, not a professionally audited password manager, secure messenger, or substitute for a reviewed security product. Do not reuse important account passwords as encryption passwords.
+> **Security note:** Android Cipher is a focused text-encryption utility, not a professionally audited password manager, secure messenger, or substitute for a reviewed security product. Do not reuse account passwords as encryption passwords.
## Features
- Password-based AES-256-GCM authenticated encryption.
- Fresh 128-bit random salt and 96-bit nonce for every encryption.
- PBKDF2-HMAC-SHA-256 key derivation (600,000 iterations for new messages).
-- Versioned, URL-safe Base64 text envelope with authentication.
+- Versioned, URL-safe Base64 text envelope; version 1 messages remain decryptable.
- Detects wrong passwords and modified ciphertext.
-- Runs locally; no network permission or account required.
-- Refined Material interface with light/dark themes, edge-to-edge system bars, custom launcher icon/splash screen and centered content on wide windows.
-- Paste, copy, share, clear-all, character count and operation progress/feedback.
-- Sensitive clipboard preview marking on Android 13+.
-- Sensitive form fields are excluded from autofill and view-state restoration; the result is read-only; copying and sharing use explicit actions.
-- Automated tests for Unicode, randomness, tampering, invalid input and old-format compatibility.
+- Encrypted/decrypted message limit of 1 MiB to bound memory and decoding work.
+- Offline operation; no account, Internet permission, analytics SDK or remote service.
+- Material 3 Expressive UI with light/dark themes, edge-to-edge insets and adaptive centered content.
+- Paste, copy, share, clear-all, Unicode-aware character count and progress/error feedback.
+- Clears the password field when an operation begins; clear-all removes only clipboard content copied by Android Cipher.
+- Espresso UI smoke tests and cryptographic regression tests.
-## Compatibility
+## Compatibility and toolchain
-- Android Studio with Android Gradle Plugin 8.13.2 support.
+- Android Studio with Android Gradle Plugin 9.5.2.
- JDK 17.
-- Gradle 8.13 (wrapper).
-- Android SDK 36.
-- Minimum Android version: API 26.
+- Gradle 9.9.1 (wrapper).
+- Android SDK Platform 36 for compilation (Android 16 SDK).
+- Minimum Android version: API 26 (Android 8.0).
+- Target SDK: API 36 (Android 16), matching the current Google Play submission requirement.
- Java source compatibility: Java 17.
-## Build
+## Build and test
-1. Clone this repository.
-2. Open the project folder in Android Studio and allow Gradle sync.
-3. Install Android SDK Platform 36 if prompted.
-4. Run the app on an emulator or device.
-
-From a terminal with JDK 17 and Android SDK configured:
+From a terminal with JDK 17 and Android SDK 36 configured:
```bash
-./gradlew clean testDebugUnitTest assembleDebug
+./gradlew clean testDebugUnitTest lintDebug assembleDebug assembleRelease bundleRelease
```
On Windows:
```powershell
-.\gradlew.bat clean testDebugUnitTest assembleDebug
+.\gradlew.bat clean testDebugUnitTest lintDebug assembleDebug assembleRelease bundleRelease
```
-The debug APK is generated at `app/build/outputs/apk/debug/app-debug.apk`.
+Debug APK: `app/build/outputs/apk/debug/app-debug.apk`
+
+Release APK: `app/build/outputs/apk/release/app-release.apk`
+
+Android App Bundle: `app/build/outputs/bundle/release/app-release.aab`
+
+Without a configured upload keystore, the local release APK/AAB is unsigned and is not suitable for Play Console submission. Debug builds use a separate `.debug` application ID.
+
+GitHub Actions runs unit tests, lint, debug/release APK and AAB builds, and Espresso smoke tests on Android API 26 and 36. Dependabot checks Gradle and GitHub Actions dependencies weekly.
+
+## Signed GitHub and Play release
+
+The signed-release workflow creates a GitHub Release containing a signed APK and AAB when the app version changes on `main`. It deliberately refuses to publish an unsigned or debug-signed APK as a stable release.
+
+To enable it, add these repository Actions secrets:
+
+- `ANDROID_KEYSTORE_BASE64`: base64 encoding of your private Android upload keystore.
+- `ANDROID_KEYSTORE_PASSWORD`: keystore password.
+- `ANDROID_KEY_ALIAS`: key alias.
+- `ANDROID_KEY_PASSWORD`: key password.
-GitHub Actions runs the unit tests and assembles a debug APK for pushes and pull requests.
+Keep the keystore and passwords private; never commit them. Once these four secrets are configured, the release workflow can publish signed APK and AAB assets automatically after a versioned merge to `main`. The workflow does not submit to Google Play; Play Console review and store listing work remain separate.
## Encrypt and decrypt
-1. Enter the text you want to protect.
-2. Enter a strong password of at least 12 characters.
+1. Enter the text you want to protect (up to 1 MiB after UTF-8 encoding).
+2. Enter a strong, unique password of at least 12 characters.
3. Select **Encrypt** and copy the resulting `AC2:` message.
-4. To decrypt, paste the complete `AC2:` message into the input field, enter the same password, and select **Decrypt**.
+4. Paste the full message back into the input, enter the same password and select **Decrypt**.
-**Keep the password safe.** It is not embedded in the encrypted message and cannot be recovered if lost. Use a unique passphrase. A password manager can help store it.
+The password is not embedded in the encrypted message and cannot be recovered if lost. The password field is cleared when an operation begins.
## Encryption format
-The text envelope is:
+The envelope is:
```text
AC2: Base64URL(version || salt || nonce || ciphertext || GCM-tag)
```
-- Version: 1 byte. New encryption writes version 2; version 1 messages remain decryptable.
+- Version: 1 byte. New encryption writes version 2; version 1 remains supported for decryption.
- Salt: 16 random bytes per message.
- Nonce: 12 random bytes per message.
- Cipher: AES/GCM/NoPadding with a 128-bit authentication tag.
-- Key derivation: PBKDF2WithHmacSHA256, 600,000 iterations for version 2 (256-bit output).
-- Version 1 compatibility: PBKDF2-HMAC-SHA-256 at 210,000 iterations.
-- Associated authenticated data binds the envelope to its format version.
+- Version 2 key derivation: PBKDF2WithHmacSHA256, 600,000 iterations, 256-bit output.
+- Version 1 key derivation: PBKDF2-HMAC-SHA-256, 210,000 iterations.
+- Associated authenticated data binds ciphertext to the format version.
-The format version identifies the cryptographic parameters. The app retains version 1 decryption support so existing Android Cipher 2.0 messages remain readable. The 600,000-iteration work factor uses OWASP's current PBKDF2-HMAC-SHA-256 password-storage recommendation as a conservative reference; actual responsiveness still needs benchmarking on supported physical devices.
+The PBKDF2 work factor uses OWASP's 600,000-iteration PBKDF2-HMAC-SHA-256 recommendation as a conservative reference. KDF latency still requires benchmarking on representative devices; a high iteration count is not a substitute for a strong passphrase or an independent security review.
## Important migration note
-The original app used Blowfish-CBC with a hardcoded key and fixed IV. That design is unauthenticated and unsuitable for new data. Version 2 does not generate legacy Blowfish ciphertext and does not automatically import old ciphertext. Keep a backup of any old data you still need; do not assume old messages can be opened by the new version.
+The original app used Blowfish-CBC with a hardcoded key and fixed IV. That design was unauthenticated and is not supported for new messages. Android Cipher 2.x does not automatically import old Blowfish ciphertext. Preserve backups of any legacy data you still need.
## Privacy and limitations
-- The app requests no internet permission and does not upload message contents.
-- The encryption password is required for every operation and is not saved by the app.
-- Clipboard contents may be visible to other apps or system clipboard history. Android Cipher marks copied content as sensitive on Android 13+, but only copy sensitive output when necessary.
-- The password-based format is portable: the same password can decrypt the message on another compatible device.
-- This release focuses on text. File encryption, secure vault storage, biometric unlock, and encrypted history are not implemented.
-- Cryptographic code should receive independent security review before being used for high-value or regulated data.
+- The app requests no Internet permission and does not upload message contents.
+- Encryption passwords are not saved to preferences or included in ciphertext.
+- The app limits messages to 1 MiB to bound work on untrusted pasted input.
+- Clipboard contents can be visible to the keyboard or other system surfaces. Android Cipher marks copied output as sensitive for modern clipboard previews and clear-all removes its own copied clip when it is still the active clip.
+- Sharing a decrypted result deliberately sends that text to the app selected in Android's Sharesheet.
+- This release focuses on text. File encryption, encrypted vault storage, biometric unlock and encrypted history are not implemented.
+- Cryptographic code has not had an independent audit. Do not use it for high-value or regulated data without professional review.
## License
@@ -96,4 +112,4 @@ This project is distributed under the GNU General Public License v3.0. See [LICE
## Contributing
-Issues and pull requests are welcome. Please include reproducible build steps and tests for changes to cryptographic formats.
+Issues and pull requests are welcome. Changes to cryptographic formats must include compatibility tests and must not silently change the interpretation of existing envelopes.
diff --git a/app/build.gradle b/app/build.gradle
index 00128b4..98b57de 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -10,12 +10,24 @@ android {
applicationId "com.example.encryptiondecryption"
minSdk 26
targetSdk 36
- versionCode 3
- versionName "2.1.0"
+ versionCode 4
+ versionName "2.2.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
+ signingConfigs {
+ release {
+ def keystorePath = System.getenv("ANDROID_KEYSTORE_PATH")
+ if (keystorePath != null && !keystorePath.isBlank()) {
+ storeFile file(keystorePath)
+ storePassword System.getenv("ANDROID_KEYSTORE_PASSWORD")
+ keyAlias System.getenv("ANDROID_KEY_ALIAS")
+ keyPassword System.getenv("ANDROID_KEY_PASSWORD")
+ }
+ }
+ }
+
buildTypes {
debug {
applicationIdSuffix ".debug"
@@ -24,6 +36,10 @@ android {
release {
minifyEnabled true
shrinkResources true
+ if (System.getenv("ANDROID_KEYSTORE_PATH") != null
+ && !System.getenv("ANDROID_KEYSTORE_PATH").isBlank()) {
+ signingConfig signingConfigs.release
+ }
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
@@ -35,13 +51,20 @@ android {
testOptions {
unitTests.returnDefaultValues = false
+ animationsDisabled = true
+ }
+
+ lint {
+ abortOnError true
+ checkReleaseBuilds true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.8.0'
- implementation 'com.google.android.material:material:1.13.0'
+ implementation 'com.google.android.material:material:1.14.0'
implementation 'androidx.core:core:1.17.0'
+ implementation 'androidx.core:core-splashscreen:1.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
diff --git a/app/src/androidTest/java/com/example/encryptiondecryption/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/encryptiondecryption/ExampleInstrumentedTest.java
index 7935e08..9d592c5 100644
--- a/app/src/androidTest/java/com/example/encryptiondecryption/ExampleInstrumentedTest.java
+++ b/app/src/androidTest/java/com/example/encryptiondecryption/ExampleInstrumentedTest.java
@@ -1,26 +1,38 @@
package com.example.encryptiondecryption;
-import android.content.Context;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
-import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import static org.junit.Assert.*;
-
-/**
- * Instrumented test, which will execute on an Android device.
- *
- * @see Testing documentation
- */
+/** Smoke tests for the main encryption screen on a real Android runtime. */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
+ @Rule
+ public ActivityScenarioRule activityRule =
+ new ActivityScenarioRule<>(MainActivity.class);
+
+ @Test
+ public void launchShowsEncryptionControlsAndResult() {
+ onView(withId(R.id.inputText)).check(matches(isDisplayed()));
+ onView(withId(R.id.passwordInput)).check(matches(isDisplayed()));
+ onView(withId(R.id.encryptButton)).check(matches(isDisplayed()));
+ onView(withId(R.id.decryptButton)).check(matches(isDisplayed()));
+ onView(withId(R.id.outputText)).check(matches(isDisplayed()));
+ }
+
@Test
- public void useAppContext() {
- // Context of the app under test.
- Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
- assertEquals("com.example.encryptiondecryption", appContext.getPackageName());
+ public void characterCounterCountsUnicodeCodePoints() {
+ activityRule.getScenario().onActivity(activity ->
+ activity.findViewById(R.id.inputText).setText("Hi 🔐"));
+ onView(withId(R.id.inputCount)).check(matches(withText("4 characters")));
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index daa9877..d78a291 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,6 +2,7 @@
MAX_TEXT_BYTES) {
+ throw new IllegalArgumentException("Text must be 1 MiB or smaller.");
+ }
validatePassword(password, true);
+ byte[] plaintextBytes = plaintext.getBytes(StandardCharsets.UTF_8);
+ if (plaintextBytes.length > MAX_TEXT_BYTES) {
+ Arrays.fill(plaintextBytes, (byte) 0);
+ throw new IllegalArgumentException("Text must be 1 MiB or smaller when encoded as UTF-8.");
+ }
+
byte[] salt = new byte[SALT_LENGTH];
byte[] nonce = new byte[NONCE_LENGTH];
- byte[] plaintextBytes = plaintext.getBytes(StandardCharsets.UTF_8);
byte[] derivedKey = null;
byte[] ciphertext = null;
@@ -87,13 +100,23 @@ public static String decrypt(String encryptedText, char[] password)
throw new IllegalArgumentException(
"This is not an Android Cipher encrypted message.");
}
+ if (encryptedText.length() > MAX_ENVELOPE_CHARS) {
+ throw new IllegalArgumentException("Encrypted text exceeds the 1 MiB message limit.");
+ }
validatePassword(password, false);
final byte[] payload;
try {
- payload = Base64.getUrlDecoder()
- .decode(encryptedText.substring(PREFIX.length()).trim());
+ String encodedPayload = encryptedText.substring(PREFIX.length()).trim();
+ if (encodedPayload.length() > MAX_ENVELOPE_CHARS - PREFIX.length()) {
+ throw new IllegalArgumentException("Encrypted text exceeds the 1 MiB message limit.");
+ }
+ payload = Base64.getUrlDecoder().decode(encodedPayload);
} catch (IllegalArgumentException exception) {
+ if (exception.getMessage() != null
+ && exception.getMessage().contains("1 MiB")) {
+ throw exception;
+ }
throw new IllegalArgumentException("The encrypted text is malformed.", exception);
}
@@ -102,6 +125,10 @@ public static String decrypt(String encryptedText, char[] password)
Arrays.fill(payload, (byte) 0);
throw new IllegalArgumentException("The encrypted text is incomplete.");
}
+ if (payload.length > MAX_PAYLOAD_BYTES) {
+ Arrays.fill(payload, (byte) 0);
+ throw new IllegalArgumentException("Encrypted text exceeds the 1 MiB message limit.");
+ }
byte[] salt = new byte[SALT_LENGTH];
byte[] nonce = new byte[NONCE_LENGTH];
@@ -133,6 +160,9 @@ public static String decrypt(String encryptedText, char[] password)
new GCMParameterSpec(TAG_LENGTH_BITS, nonce));
cipher.updateAAD(associatedData(version));
plaintextBytes = cipher.doFinal(ciphertext);
+ if (plaintextBytes.length > MAX_TEXT_BYTES) {
+ throw new IllegalArgumentException("Decrypted text exceeds the 1 MiB message limit.");
+ }
return new String(plaintextBytes, StandardCharsets.UTF_8);
} finally {
Arrays.fill(payload, (byte) 0);
diff --git a/app/src/main/java/com/example/encryptiondecryption/MainActivity.java b/app/src/main/java/com/example/encryptiondecryption/MainActivity.java
index cb5c19d..61b9b7a 100644
--- a/app/src/main/java/com/example/encryptiondecryption/MainActivity.java
+++ b/app/src/main/java/com/example/encryptiondecryption/MainActivity.java
@@ -22,6 +22,7 @@
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
+import androidx.core.splashscreen.SplashScreen;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.snackbar.Snackbar;
@@ -53,8 +54,9 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
+ SplashScreen.installSplashScreen(this);
super.onCreate(savedInstanceState);
- WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
+ WindowCompat.enableEdgeToEdge(getWindow());
setContentView(R.layout.activity_main);
rootView = findViewById(R.id.rootView);
@@ -89,7 +91,8 @@ private void applySystemBarInsets() {
controller.setAppearanceLightNavigationBars(!dark);
ViewCompat.setOnApplyWindowInsetsListener(rootView, (view, windowInsets) -> {
- Insets bars = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
+ Insets bars = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()
+ | WindowInsetsCompat.Type.displayCutout());
Insets ime = windowInsets.getInsets(WindowInsetsCompat.Type.ime());
view.setPadding(view.getPaddingLeft(), bars.top, view.getPaddingRight(),
Math.max(bars.bottom, ime.bottom) + 12);
@@ -166,6 +169,7 @@ private void processText(boolean encrypt) {
char[] passwordChars = new char[passwordLength];
passwordEditable.getChars(0, passwordLength, passwordChars, 0);
+ passwordInput.setText("");
outputText.setText("");
copyButton.setEnabled(false);
shareButton.setEnabled(false);
@@ -277,6 +281,7 @@ private void shareOutput() {
private void clearFields() {
if (processing) return;
+ clearAppClipboardIfOwned();
inputText.setText("");
passwordInput.setText("");
outputText.setText("");
@@ -290,8 +295,27 @@ private void clearFields() {
showMessage(getString(R.string.message_cleared));
}
+ private void clearAppClipboardIfOwned() {
+ ClipboardManager clipboard =
+ (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
+ if (clipboard == null || !clipboard.hasPrimaryClip()) return;
+
+ ClipDescription description = clipboard.getPrimaryClipDescription();
+ if (description == null
+ || !getString(R.string.clip_label).contentEquals(description.getLabel())) {
+ return;
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+ clipboard.clearPrimaryClip();
+ } else {
+ clipboard.setPrimaryClip(ClipData.newPlainText("", ""));
+ }
+ }
+
private void updateCharacterCount() {
- int count = inputText.getText() == null ? 0 : inputText.getText().length();
+ CharSequence text = inputText.getText();
+ int count = text == null ? 0 : Character.codePointCount(text, 0, text.length());
inputCount.setText(getString(R.string.character_count, count));
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 1c81b67..b8018db 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -82,7 +82,7 @@
android:layout_marginTop="26dp"
android:text="@string/hero_title"
android:textColor="?attr/colorOnBackground"
- android:textSize="29sp"
+ android:textSize="30sp"
android:fontFamily="sans"
android:letterSpacing="-0.02"
android:textStyle="bold" />
@@ -168,7 +168,7 @@
+ android:textSize="14sp"
+ android:accessibilityLiveRegion="polite" />
-
-
\ No newline at end of file
diff --git a/app/src/main/res/values-night-v31/themes.xml b/app/src/main/res/values-night-v31/themes.xml
deleted file mode 100644
index e7d2146..0000000
--- a/app/src/main/res/values-night-v31/themes.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml
index 482b210..ceb3eea 100644
--- a/app/src/main/res/values-night/colors.xml
+++ b/app/src/main/res/values-night/colors.xml
@@ -1,6 +1,8 @@
#0B1220
+ #111C2B
+ #E7F1F7
#55D6BE
#06231F
#142B32
diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
index d860cf3..9933877 100644
--- a/app/src/main/res/values-night/themes.xml
+++ b/app/src/main/res/values-night/themes.xml
@@ -1,5 +1,7 @@
-
-
\ No newline at end of file
+
diff --git a/app/src/main/res/values-v27/themes.xml b/app/src/main/res/values-v27/themes.xml
deleted file mode 100644
index 56b50de..0000000
--- a/app/src/main/res/values-v27/themes.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/values-v31/themes.xml b/app/src/main/res/values-v31/themes.xml
deleted file mode 100644
index c134404..0000000
--- a/app/src/main/res/values-v31/themes.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index efb32f1..c621d0d 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,6 +1,8 @@
#F4F7FB
+ #FFFFFF
+ #172B3A
#087F75
#FFFFFF
#E5F5F1
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 5542aac..f8ac020 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,10 +1,10 @@
Android Cipher
PRIVATE BY DESIGN
- v2.1
+ v2.2
Android Cipher
Your words. Your privacy.
- Encrypt and decrypt text locally. Your password never leaves this device.
+ Private text encryption that runs entirely on this device — no account or network connection required.
Authenticated encryption
AES-256-GCM · Random salt and nonce · Offline
Message
@@ -22,8 +22,8 @@
Copy
Share
Clear all
- Everything is processed on this device. Your text and password are never uploaded by Android Cipher.
- ANDROID CIPHER 2.1 · OFFLINE TEXT ENCRYPTION
+ Everything is processed on this device. Messages are limited to 1 MiB. Your text and password are never uploaded by Android Cipher.
+ ANDROID CIPHER 2.2 · OFFLINE TEXT ENCRYPTION
READY
ERROR
ENCRYPTING…
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 6fd87c8..93fb863 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -1,20 +1,22 @@
-
-
+
+
diff --git a/app/src/test/java/com/example/encryptiondecryption/CryptoManagerTest.java b/app/src/test/java/com/example/encryptiondecryption/CryptoManagerTest.java
index f148c55..ddabdd9 100644
--- a/app/src/test/java/com/example/encryptiondecryption/CryptoManagerTest.java
+++ b/app/src/test/java/com/example/encryptiondecryption/CryptoManagerTest.java
@@ -76,6 +76,22 @@ public void shortEncryptionPasswordIsRejected() throws Exception {
CryptoManager.encrypt("secret", "short".toCharArray());
}
+
+ @Test(expected = IllegalArgumentException.class)
+ public void rejectsPlaintextLargerThanOneMiB() throws Exception {
+ CryptoManager.encrypt("a".repeat(CryptoManager.MAX_TEXT_BYTES + 1), PASSWORD);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void rejectsUtf8PayloadLargerThanOneMiB() throws Exception {
+ CryptoManager.encrypt("界".repeat(400_000), PASSWORD);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void rejectsOversizedEnvelopeBeforeBase64Decoding() throws Exception {
+ CryptoManager.decrypt("AC2:" + "A".repeat(1_500_000), PASSWORD);
+ }
+
private static String createLegacyVersionOneMessage(String plaintext)
throws Exception {
byte[] salt = new byte[16];
diff --git a/build.gradle b/build.gradle
index 1a2db8d..c629dc7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,5 @@
plugins {
- id 'com.android.application' version '8.13.2' apply false
+ id 'com.android.application' version '9.5.2' apply false
}
tasks.register('clean', Delete) {
diff --git a/gradle.properties b/gradle.properties
index dab7c28..0f6815a 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,21 +1,6 @@
# Project-wide Gradle settings.
-# IDE (e.g. Android Studio) users:
-# Gradle settings configured through the IDE *will override*
-# any settings specified in this file.
-# For more details on how to configure your build environment visit
-# http://www.gradle.org/docs/current/userguide/build_environment.html
-# Specifies the JVM arguments used for the daemon process.
-# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
-# When configured, Gradle will run in incubating parallel mode.
-# This option should only be used with decoupled projects. More details, visit
-# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
-# AndroidX package structure to make it clearer which packages are bundled with the
-# Android operating system, and which are packaged with your app"s APK
-# https://developer.android.com/topic/libraries/support-library/androidx-rn
+org.gradle.caching=true
+org.gradle.parallel=true
android.useAndroidX=true
-# Enables namespacing of each library's R class so that its R class includes only the
-# resources declared in the library itself and none from the library's dependencies,
-# thereby reducing the size of the R class for that library
-android.nonTransitiveRClass=true
\ No newline at end of file
+android.nonTransitiveRClass=true
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 37f853b..60d3852 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME