MuntashirAkon/AppManager · error · CryptoException

Unsupported mode ${mParentMode}

Error message

Unsupported mode ${mParentMode}

What it means

AESCrypto's constructor throws this CryptoException when invoked with a mode other than the supported CryptoUtils.MODE_AES / MODE_RSA (and EC-related modes handled above) — the default branch of its switch. It is a programming/configuration error: an unrecognized crypto mode constant was passed.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/crypto/AESCrypto.java:95

                    // No encryption key provided, generate one
                    mSecretKey = RSACrypto.generateAesKey();
                } else {
                    // Encryption key provided
                    mSecretKey = RSACrypto.decryptAesKey(encryptedAesKey);
                }
                break;
            case CryptoUtils.MODE_ECC:
                // Hybrid encryption using ECC
                if (encryptedAesKey == null) {
                    // No encryption key provided, generate one
                    mSecretKey = ECCCrypto.generateAesKey();
                } else {
                    // Encryption key provided
                    mSecretKey = ECCCrypto.decryptAesKey(encryptedAesKey);
                }
                break;
            default:
                throw new CryptoException("Unsupported mode " + mParentMode);
        }
    }

    public void setMacSizeBits(int macSizeBits) {
        if (macSizeBits == MAC_SIZE_BITS || macSizeBits == MAC_SIZE_BITS_OLD) {
            mMacSizeBits = macSizeBits;
        }
    }

    @NonNull
    private AEADParameters getParams() {
        // We need to generate it dynamically due to MAC size issues
        return new AEADParameters(new KeyParameter(mSecretKey.getEncoded()), mMacSizeBits, mIv);
    }

    @CallSuper
    @NonNull
    protected byte[] getEncryptedAesKey() throws CryptoException {

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Only pass modes defined and supported by CryptoUtils (MODE_AES, MODE_RSA)
  2. Validate/whitelist the mode before constructing AESCrypto, falling back to MODE_AES
  3. If a new mode was added to CryptoUtils, extend AESCrypto's switch to handle it
  4. Migrate stale persisted mode values to current constants

Example fix

// before
AESCrypto crypto = new AESCrypto(someIntMode); // unvalidated
// after
if (mode != CryptoUtils.MODE_AES && mode != CryptoUtils.MODE_RSA) {
    mode = CryptoUtils.MODE_AES; // safe default
}
AESCrypto crypto = new AESCrypto(mode);
Defensive patterns

Strategy: validation

Validate before calling

Set<Integer> supported = new HashSet<>(Arrays.asList(
        CryptoUtils.MODE_AES, CryptoUtils.MODE_RSA));
if (!supported.contains(mode)) {
    throw new IllegalArgumentException("Unsupported crypto mode: " + mode);
}

Type guard

boolean isSupportedCryptoMode(int mode) {
    return mode == CryptoUtils.MODE_AES || mode == CryptoUtils.MODE_RSA;
}

Try / catch

try {
    crypto = new AESCrypto(mode);
} catch (CryptoException e) {
    Log.e(TAG, "Bad crypto mode " + mode, e);
    crypto = new AESCrypto(CryptoUtils.MODE_AES); // safe default
}

Prevention

When it happens

Trigger: Passing an undefined mode int to the AESCrypto constructor, e.g. CryptoUtils.MODE_GCM, a custom mode constant, or garbage from an unvalidated persisted preference/Intent extra.

Common situations: Refactors that add new CryptoUtils modes without updating AESCrypto; stale mode values read from old encrypted session files or SharedPreferences; mixing up CryptoUtils constants across versions.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/f78da6a3b4717808. Report an issue: GitHub.