我正在尝试将语音文件加密后解密,然后将其上传到Firebase,然后再下载。对于加密/解密,我使用的是EasyCrypt
当我在另一台设备上获得下载的文件并尝试将其解密时:
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);
解密完成99%,然后出现以下错误:
E /无法写入文件。:java.io.IOException:完成时出错 密码
这是错误的完整堆栈:
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
注意:被测试的设备运行的Android版本不同,一个是棉花糖,另一个是Oreo。
答案 0 :(得分:2)
我相信您的问题是设备没有运行用于加密和解密的相同OpenSSL版本。我在您的错误日志中搜索了另一个错误。
原因:javax.crypto.BadPaddingException:错误:1e06b065:密码功能:EVP_DecryptFinal_ex:BAD_DECRYPT
查看此SO question以获得更多信息。我知道这并不能完全回答您的问题,但是希望它能帮助您入门。