'error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT

I'm getting the following error when i tried to decrypt a list of ogg files but when i try to decrypt only one it works this is my code.

  for (IpstoriResponse ipstori: descargas) {
                        Executors.newSingleThreadExecutor().execute(() -> {
                            ipstori.setAudioHistory(getOfflineFile(ipstori.getAudioPath(), ipstori.getAudioCle(), ipstori.getAudioIv(), requireContext(), ipstori.getAudioCle()));
                            prepareList.add(...);
                        });
                    }
            }

  private String getOfflineFile(String input, String key, String iv, Context context, String name){
    String result = null;
    try {
        File initialFile = new File(input);
        InputStream inputStream = new FileInputStream(initialFile);
        File outputDir = context.getCacheDir(); // context being the Activity pointer
        File outputFile = File.createTempFile(name, ".ogg", outputDir);

        FileOutputStream fos = new FileOutputStream(outputFile);

        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        SecretKey secretKey = makeKey(key);
        IvParameterSpec ivParameterSpec = makeIv(iv);

        cipher.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec);
        CipherInputStream cipherInputStream = new CipherInputStream(inputStream, cipher);
        byte[] buffer = new byte[8192];
        int nread;
        while ((nread = cipherInputStream.read(buffer)) > 0) {
            fos.write(buffer, 0, nread);
        }
        fos.flush();
        fos.close();
        cipherInputStream.close();
        result = outputFile.getPath();
        tempFiles.add(result);
    } catch (Exception ex) {
        ...
    }

    return result;
}

that's really weird cause when you try to decrypt only one element of the list the code works fine



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source