MuntashirAkon/AppManager · error · BackupException

Failed to encrypt checksums.txt

Error message

Failed to encrypt checksums.txt

What it means

After writing metadata and closing the checksum file, convert() encrypts checksums.txt via mBackupItem.encrypt(). An IOException is wrapped as this BackupException (note: no cause is attached). It means the encryption step for the checksum file failed.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/backup/convert/TBConverter.java:153

            }
            if (mDestMetadata.info.flags.backupData()) {
                backupData();
            }
            // Write modified metadata
            try {
                Map<String, String> filenameChecksumMap = MetadataManager.writeMetadata(mDestMetadata, mBackupItem);
                for (Map.Entry<String, String> filenameChecksumPair : filenameChecksumMap.entrySet()) {
                    mChecksum.add(filenameChecksumPair.getKey(), filenameChecksumPair.getValue());
                }
            } catch (IOException e) {
                throw new BackupException("Failed to write metadata.", e);
            }
            mChecksum.close();
            // Encrypt checksum
            try {
                mBackupItem.encrypt(new Path[]{mChecksum.getFile()});
            } catch (IOException e) {
                throw new BackupException("Failed to encrypt checksums.txt");
            }
            // Replace current backup:
            // There's hardly any chance of getting a false here but checks are done anyway.
            try {
                mBackupItem.commit();
            } catch (Exception e) {
                throw new BackupException("Could not finalise backup.", e);
            }
            backupSuccess = true;
        } catch (BackupException e) {
            throw e;
        } catch (Throwable th) {
            throw new BackupException("Unknown error occurred.", th);
        } finally {
            mBackupItem.cleanup();
            if (backupSuccess) {
                BackupUtils.putBackupToDbAndBroadcast(ContextUtils.getContext(), mDestMetadata);
            }

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Verify the destination crypto settings (key, alias, algorithm) are valid before conversion; re-select the encryption key.
  2. Check free space and writability of the backup directory.
  3. Delete any leftover plaintext/ciphertext checksum files from a failed run and retry.
  4. Inspect logs of the crypto layer (CryptoUtils) since this BackupException does not carry the original cause.

Example fix

// before
throw new BackupException("Failed to encrypt checksums.txt");
// after
throw new BackupException("Failed to encrypt checksums.txt", e); // preserve cause for diagnosis
Defensive patterns

Strategy: validation

Validate before calling

// Validate crypto capability before conversion
if (mBackupItem.isEncrypted()) {
    if (!CryptoUtils.canEncrypt(mDestMetadata.crypto)) throw new IllegalStateException("Crypto not ready: check key/alias/algorithm");
}

Type guard

fun CryptoInfo?.readyForEncryption(): Boolean = this != null && keyAlias != null && algo != null && CryptoUtils.keyExists(keyAlias)

Try / catch

try {
    converter.convert();
} catch (BackupException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Failed to encrypt checksums")) {
        Log.e(TAG, "Checksum encryption failed — verify keystore and algorithm");
    }
}

Prevention

When it happens

Trigger: mBackupItem.encrypt(new Path[]{mChecksum.getFile()}) throws IOException: the crypto engine fails to open the key/keystore, the cipher cannot initialize, or I/O fails reading the plaintext/writing the ciphertext file.

Common situations: Keystore removed or key invalidated after conversion started; unsupported or mismatched crypto algorithm configured for the destination format; ciphertext output file already exists and cannot be replaced; storage I/O error during write.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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