我已经对我要保护的音频文件进行了加密和解密。但在进行解密后,它会显示MediaPlayer的一些警告日志,而MediaPlayer也无法正常工作。
所以我只是想知道加密/解密过程是否损坏了我的音频文件?
这里提到了日志:
11-14 13:41:42.136: W/System.err(17602): java.io.IOException: Prepare failed.: status=0xFFFFFFFC
11-14 13:41:42.136: W/System.err(17602): at android.media.MediaPlayer.prepare(Native Method)
11-14 13:41:42.136: W/System.err(17602): at com.zenagestudios.itaaleemlehra.LessonPlayActivity.startPlayer(LessonPlayActivity.java:293)
11-14 13:41:42.136: W/System.err(17602): at com.zenagestudios.itaaleemlehra.LessonPlayActivity.onClick(LessonPlayActivity.java:446)
11-14 13:41:42.136: W/System.err(17602): at android.view.View.performClick(View.java:2461)
11-14 13:41:42.136: W/System.err(17602): at android.view.View$PerformClick.run(View.java:8890)
11-14 13:41:42.136: W/System.err(17602): at android.os.Handler.handleCallback(Handler.java:587)
11-14 13:41:42.136: W/System.err(17602): at android.os.Handler.dispatchMessage(Handler.java:92)
11-14 13:41:42.136: W/System.err(17602): at android.os.Looper.loop(Looper.java:123)
11-14 13:41:42.136: W/System.err(17602): at android.app.ActivityThread.main(ActivityThread.java:4632)
11-14 13:41:42.136: W/System.err(17602): at java.lang.reflect.Method.invokeNative(Native Method)
11-14 13:41:42.136: W/System.err(17602): at java.lang.reflect.Method.invoke(Method.java:521)
11-14 13:41:42.136: W/System.err(17602): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-14 13:41:42.136: W/System.err(17602): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-14 13:41:42.136: W/System.err(17602): at dalvik.system.NativeStart.main(Native Method)
我为示例XML文件尝试了相同的加密/解密代码,它对XML文件工作正常。
以下是我用于加密/解密的代码:
public void encrypt(InputStream in, OutputStream out){
try {
// Bytes written to out will be encrypted
out = new CipherOutputStream(out, ecipher);
// Read in the cleartext bytes and write to out to encrypt
int numRead = 0;
while ((numRead = in.read(buf)) >= 0){
out.write(buf, 0, numRead);
}
System.out.println("Database Encrypted");
out.close();
}
catch (java.io.IOException e){
e.printStackTrace();
}
}
public void decrypt(InputStream in, OutputStream out){
try {
//staticdata. dialog = ProgressDialog.show(mContext, "","Loading. Please wait...", false);
// Bytes read from in will be decrypted
in = new CipherInputStream(in, dcipher);
// Read in the decrypted bytes and write the cleartext to out
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
System.out.println("Database Decrypted");
out.close();
}
catch (java.io.IOException e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
是的,您似乎没有正确加密/解密文件。您可以在简单的文本文件上测试加密/解密,以查看文件是否保持不变。