#StackBounty: #java #android #firebase #encryption #cryptography Error while finalizing cipher with EasyCrypt library on another device

Bounty: 150

I am trying to decrypt a voice file after encrypting it, uploading it to Firebase then downloading it. and for the encryption/decryption I am using EasyCrypt

  • The encrypting and uploading done successfully.
  • The downloading is done successfully.
  • I have checked the encrypting key and it is the same as the
    decrypting one.
  • The permissions are granted.
    • The decryption works on the same device even after downloading the new file.

When I get the downloaded file on another device and try to decrypt it like:

final File decryptedVoice = new File(myFilePath + "/" + dateHolder + ".mp4");
final File encryptedFile = new File(voiceURL);
progressBar.setVisibility(View.VISIBLE);
ECSymmetric ecSymmetric = new ECSymmetric();
ecSymmetric.decrypt(encryptedFile, voiceKey, new ECResultListener() {
    @Override
    public void onProgress(int i, long l, long l1) {
        Log.e("EncryptedFile", encryptedFile.getPath());
        Log.e("DecryptedFile", decryptedVoice.getAbsolutePath());
        Log.e(" DecryptionKey", decryptionKey);
        Log.i("VoiceDecryption", String.valueOf((l*100)/l1));
    }

    @Override
    public <T> void onSuccess(T t) {
        progressBar.setVisibility(View.GONE);
        pause.setVisibility(View.VISIBLE);
        try {
            mediaPlayer.setDataSource(decryptedVoice.getAbsolutePath());
            mediaPlayer.prepare();
            mediaPlayer.setVolume(10,10);
            mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    seekBar.setMax(mediaPlayer.getDuration());
                    mediaPlayer.start();
                    update(mediaPlayer, time, seekBar);


                }
            });

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onFailure(String s, Exception e) {
        Log.e(s, e.toString());
    }
}, decryptedVoice);

The decryption is done 99% then I get the following error:

E/Cannot write to file.: java.io.IOException: Error while finalizing
cipher

Here is the full stack of the error:

08-18 18:54:30.578 30039-30989/com.berbangchat.me I/VoiceDecryption: 99
08-18 18:54:30.583 30039-30989/com.berbangchat.me W/System.err: java.io.IOException: Error while finalizing cipher
        at javax.crypto.CipherInputStream.fillBuffer(CipherInputStream.java:104)
        at javax.crypto.CipherInputStream.read(CipherInputStream.java:155)
        at java.io.InputStream.read(InputStream.java:162)
        at com.pvryan.easycrypt.symmetric.performDecrypt.invoke$easycrypt_release(performDecrypt.kt:124)
        at com.pvryan.easycrypt.symmetric.ECSymmetric$decrypt$1.invoke(ECSymmetric.kt:209)
        at com.pvryan.easycrypt.symmetric.ECSymmetric$decrypt$1.invoke(ECSymmetric.kt:44)
        at org.jetbrains.anko.AsyncKt$doAsync$1.invoke(Async.kt:140)
        at org.jetbrains.anko.AsyncKt$doAsync$1.invoke(Async.kt)
        at org.jetbrains.anko.AsyncKt$sam$Callable$761a5578.call(Async.kt)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)
    Caused by: javax.crypto.BadPaddingException: error:1e06b065:Cipher functions:EVP_DecryptFinal_ex:BAD_DECRYPT
08-18 18:54:30.583 30039-30989/com.berbangchat.me W/System.err:     at com.android.org.conscrypt.NativeCrypto.EVP_CipherFinal_ex(Native Method)
08-18 18:54:30.583 30039-30989/com.berbangchat.me W/System.err:     at com.android.org.conscrypt.OpenSSLCipher$EVP_CIPHER.doFinalInternal(OpenSSLCipher.java:568)
        at com.android.org.conscrypt.OpenSSLCipher.engineDoFinal(OpenSSLCipher.java:385)
        at javax.crypto.Cipher.doFinal(Cipher.java:1476)
08-18 18:54:30.583 30039-30989/com.berbangchat.me W/System.err:     at javax.crypto.CipherInputStream.fillBuffer(CipherInputStream.java:102)
        ... 14 more
08-18 18:54:30.583 30039-30989/com.berbangchat.me E/CipherError: Cannot write to file. : java.io.IOException: Error while finalizing cipher

Note: The tested devices are not running the same android versions, one is Marshmallow and one is Oreo.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.