{"record":{"id":"e785e33e5cfccc78","repo":"MuntashirAkon/AppManager","slug":"failed-to-encrypt-checksums-txt-tbconverter","errorCode":null,"errorMessage":"Failed to encrypt checksums.txt","messagePattern":"Failed to encrypt checksums\\.txt","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/convert/TBConverter.java","lineNumber":153,"sourceCode":"            }\n            if (mDestMetadata.info.flags.backupData()) {\n                backupData();\n            }\n            // Write modified metadata\n            try {\n                Map<String, String> filenameChecksumMap = MetadataManager.writeMetadata(mDestMetadata, mBackupItem);\n                for (Map.Entry<String, String> filenameChecksumPair : filenameChecksumMap.entrySet()) {\n                    mChecksum.add(filenameChecksumPair.getKey(), filenameChecksumPair.getValue());\n                }\n            } catch (IOException e) {\n                throw new BackupException(\"Failed to write metadata.\", e);\n            }\n            mChecksum.close();\n            // Encrypt checksum\n            try {\n                mBackupItem.encrypt(new Path[]{mChecksum.getFile()});\n            } catch (IOException e) {\n                throw new BackupException(\"Failed to encrypt checksums.txt\");\n            }\n            // Replace current backup:\n            // There's hardly any chance of getting a false here but checks are done anyway.\n            try {\n                mBackupItem.commit();\n            } catch (Exception e) {\n                throw new BackupException(\"Could not finalise backup.\", e);\n            }\n            backupSuccess = true;\n        } catch (BackupException e) {\n            throw e;\n        } catch (Throwable th) {\n            throw new BackupException(\"Unknown error occurred.\", th);\n        } finally {\n            mBackupItem.cleanup();\n            if (backupSuccess) {\n                BackupUtils.putBackupToDbAndBroadcast(ContextUtils.getContext(), mDestMetadata);\n            }","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/convert/TBConverter.java#L135-L171","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the destination crypto settings (key, alias, algorithm) are valid before conversion; re-select the encryption key.","Check free space and writability of the backup directory.","Delete any leftover plaintext/ciphertext checksum files from a failed run and retry.","Inspect logs of the crypto layer (CryptoUtils) since this BackupException does not carry the original cause."],"exampleFix":"// before\nthrow new BackupException(\"Failed to encrypt checksums.txt\");\n// after\nthrow new BackupException(\"Failed to encrypt checksums.txt\", e); // preserve cause for diagnosis","handlingStrategy":"validation","validationCode":"// Validate crypto capability before conversion\nif (mBackupItem.isEncrypted()) {\n    if (!CryptoUtils.canEncrypt(mDestMetadata.crypto)) throw new IllegalStateException(\"Crypto not ready: check key/alias/algorithm\");\n}","typeGuard":"fun CryptoInfo?.readyForEncryption(): Boolean = this != null && keyAlias != null && algo != null && CryptoUtils.keyExists(keyAlias)","tryCatchPattern":"try {\n    converter.convert();\n} catch (BackupException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to encrypt checksums\")) {\n        Log.e(TAG, \"Checksum encryption failed — verify keystore and algorithm\");\n    }\n}","preventionTips":["Pre-validate the keystore key and cipher before starting conversion.","Use a supported algorithm/key combination for the destination format version.","Note this exception omits its cause — enable crypto-layer logging for diagnosis."],"tags":["crypto","encryption","checksum"],"backgroundTag":"file-write-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}