我在从隐藏中读取解密的数据时遇到问题。看来我无法正确完成流式传输。我假装隐藏有问题,因为当我切换proxyStream(仅加密部分)而不通过隐藏运行它时,一切都按预期工作。我还假设写入可以,没有任何异常,我可以在磁盘上找到加密的文件。
我正在通过contentprovider代理我的数据,以允许其他应用程序在用户需要时读取解密的数据。(共享,...)
在我的内容提供者中,我使用openFile方法允许contentResolvers读取数据
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
try {
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
String name = uri.getLastPathSegment();
File file = new File(name);
InputStream fileContents = mStorageProxy.getDecryptInputStream(file);
ParcelFileDescriptor.AutoCloseOutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]);
PipeThread pipeThread = new PipeThread(fileContents, stream);
pipeThread.start();
return pipe[0];
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
我猜在Facebook应用程序Facebook android团队中,可能宁愿使用query()
发送字节数组的标准方法,但MediaStore.MediaColumns()
这种方法不适合我,因为我不仅在加密媒体文件,而且还更喜欢流的方法。
这就是我从Inpustream阅读的方式。它基本上是两个parcelFileDescriptor之间的管道。inputstream来自隐藏,它是一个FileInputstream,它包装到BufferedInputStream原本中。
static class PipeThread extends Thread {
InputStream input;
OutputStream out;
PipeThread(InputStream inputStream, OutputStream out) {
this.input=inputStream;
this.out=out;
}
@Override
public void run() {
byte[] buf=new byte[1024];
int len;
try {
while ((len=input.read(buf)) > 0) {
out.write(buf, 0, len);
}
input.close();
out.flush();
out.close();
}
catch (IOException e) {
Log.e(getClass().getSimpleName(),
"Exception transferring file", e);
}
}
}
我尝试了其他方法来读取流,所以这实际上不应该是问题。
最后,这是我经常遇到的例外。您知道可能是什么问题吗?它指向本地电话,我迷路了。
Exception transferring file
com.facebook.crypto.cipher.NativeGCMCipherException: decryptFinal
at com.facebook.crypto.cipher.NativeGCMCipher.decryptFinal(NativeGCMCipher.java:108)
at com.facebook.crypto.streams.NativeGCMCipherInputStream.ensureTagValid(NativeGCMCipherInputStream.java:126)
at com.facebook.crypto.streams.NativeGCMCipherInputStream.read(NativeGCMCipherInputStream.java:91)
at com.facebook.crypto.streams.NativeGCMCipherInputStream.read(NativeGCMCipherInputStream.java:76)
编辑:看起来流工作正常,但失败的是从中读取的最后一次迭代。当我使用缓冲区时,似乎缓冲区更大,然后重新存储数据的数量导致了此问题。我一直在寻找隐瞒的来源,从这方面看似乎还可以。它不是可以在本机层的某个地方失败吗?注意:我设法获得了解密文件,除了最后一个字节。.例如,我有一个不完整的图像文件(最后几千个像素未显示)
这已在https://github.com/facebook/conceal/issues/24中解决。为了后代的缘故,这里的问题是作者忘记了在输出流上调用close()。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句