简体   繁体   English

直接从CipherInputStream解密和读取mp3文件,而无需存储

[英]Decrypt and read mp3 file directly from CipherInputStream without storing

I'm downloading and encrypting mp3 files in my android apps. 我正在Android应用程序中下载和加密mp3文件。 But I'm trying to decrypt and READ the files without writing the file back to file system. 但是我试图解密和读取文件,而不将文件写回到文件系统。 When I try to use CipherInputStream to stream the mp3 to android Mediaplayer API, It cannot recognise the file. 当我尝试使用CipherInputStream将mp3流传输到android Mediaplayer API时,它无法识别该文件。 However, when I try to to convert to Byte array and stream it as ByteArrayInputStream, it works but I don't want to this because it could take much time for larger files and store the data in JVM. 但是,当我尝试转换为Byte数组并将其作为ByteArrayInputStream进行流传输时,它可以工作,但是我不想这样做,因为较大的文件和将数据存储在JVM中可能会花费很多时间。

Here is my code 这是我的代码

FileInputStream fis = new FileInputStream(file);
CipherInputStream cis = new CipherInputStream(fis, cipher);
mbuffer = new ByteArrayInputStream(getByte(cis));
Response streamResponse = new Response(Status.OK, mimeType, mbuffer);

The above code works fine but the problem with this 上面的代码工作正常,但与此有关的问题

new ByteArrayInputStream(getByte(cis));

in getByte method, I convert CipherInputStream to byte then convert it back to InputStream . getByte方法中,我将CipherInputStream转换为byte,然后将其转换回InputStream

I'm trying to stream cis directly to 我正在尝试直接将顺式流式

Response streamResponse = new Response(Status.OK, mimeType, cis);

But doesn't work with MediaPlayer 但不适用于MediaPlayer

         File tempMp3 = File.createTempFile("kurchina", "mp3", getCacheDir());

         tempMp3.deleteOnExit();

         FileOutputStream fos = new FileOutputStream(tempMp3);

         fos.write(mp3SoundByteArray);

         fos.close();



         FileInputStream fis = new FileInputStream(tempMp3);

         mp.setDataSource(fis.getFD());



         mp.prepare();

         mp.start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM