{"record":{"id":"5e7aad0a4dd8a1ee","repo":"MuntashirAkon/AppManager","slug":"failed-to-encrypt-sbconverter","errorCode":null,"errorMessage":"Failed to encrypt ","messagePattern":"Failed to encrypt ","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/convert/SBConverter.java","lineNumber":194,"sourceCode":"                mChecksum.add(CERT_PREFIX + i, checksums[i]);\n            }\n        } catch (Exception ignore) {\n        }\n        // Backup APK files\n        String[] apkFiles = ArrayUtils.appendElement(String.class, mDestMetadata.metadata.splitConfigs, mDestMetadata.metadata.apkName);\n        String sourceBackupFilePrefix = BackupUtils.getSourceFilePrefix(getExt(mDestMetadata.info.tarType));\n        Path[] sourceFiles;\n        try {\n            // We have to specify APK files because the folder may contain many\n            sourceFiles = TarUtils.create(mDestMetadata.info.tarType, sourceDir, mBackupItem.getUnencryptedBackupPath(), sourceBackupFilePrefix,\n                    apkFiles, null, null, false).toArray(new Path[0]);\n        } catch (Throwable th) {\n            throw new BackupException(\"APK files backup is requested but no APK files have been backed up.\", th);\n        }\n        try {\n            sourceFiles = mBackupItem.encrypt(sourceFiles);\n        } catch (IOException e) {\n            throw new BackupException(\"Failed to encrypt \" + Arrays.toString(sourceFiles));\n        }\n        for (Path file : sourceFiles) {\n            mChecksum.add(file.getName(), DigestUtils.getHexDigest(mDestMetadata.info.checksumAlgo, file));\n        }\n    }\n\n    private void backupData() throws BackupException {\n        List<Path> dataFiles = new ArrayList<>(3);\n        try {\n            if (mDestMetadata.info.flags.backupInternalData()) {\n                dataFiles.add(getIntDataFile());\n            }\n            if (mDestMetadata.info.flags.backupExternalData()) {\n                dataFiles.add(getExtDataFile());\n            }\n            if (mDestMetadata.info.flags.backupMediaObb()) {\n                dataFiles.add(getObbFile());\n            }","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/convert/SBConverter.java#L176-L212","documentation":"Thrown by SBConverter.backupApkFile when mBackupItem.encrypt() throws IOException while encrypting the freshly created APK backup archive(s). The message uses Arrays.toString(sourceFiles), so the file list in the message shows the pre-encryption paths that failed to encrypt.","triggerScenarios":"An encrypted backup was requested (crypto flag set in metadata) and encrypt() failed, e.g. wrong/missing encryption key or password, unsupported cipher in the backup item, output file not writable, or disk full while writing the encrypted copy of the tar in mBackupItem.getUnencryptedBackupPath().","commonSituations":"User changed their backup password/key between runs; converting a backup with encryption enabled but the keystore alias or password is unavailable; low storage on the device so the encrypted output cannot be written.","solutions":["Verify the encryption credentials (password/key/keystore alias) configured for the backup item are correct and available.","Check free disk space in the backup destination before converting.","Confirm the backup destination path is writable (storage permissions, scoped-storage on Android 11+).","Either fix encryption settings or disable encryption in destination metadata (crypto flag) so encrypt() is not invoked.","Retry the conversion; transient I/O failures (e.g., media store sync) can cause spurious IOExceptions."],"exampleFix":"// before: encrypted metadata with stale key\nmetadataV2.crypto = true;\n// after: ensure credentials match or disable encryption\nif (encryptionKey == null) {\n    metadataV2.crypto = false;\n} else {\n    metadataV2.crypto = true; // key verified against keystore beforehand\n}","handlingStrategy":"try-catch","validationCode":"if (metadata.info.crypto) {\n    if (encryptionKey == null || !keyExistsInKeystore(alias))\n        throw new IllegalStateException(\"encryption requested but credentials unavailable\");\n}\nif (destDir.getUsableSpace() < estimatedSize * 2)\n    throw new IllegalStateException(\"insufficient space for encrypted copy\");","typeGuard":null,"tryCatchPattern":"try { converter.convert(); }\ncatch (BackupException e) {\n    if (e.getMessage().startsWith(\"Failed to encrypt\")) {\n        // re-prompt for password or disable encryption, then retry\n    }\n}","preventionTips":["Keep backup encryption keys/passwords stable across conversion sessions","Check free disk space before encrypted conversions","Test encryption settings with a small backup first","Disable encryption if credentials are unavailable rather than forcing it"],"tags":["android","backup","encryption","io"],"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"}