java - facebook Conceal 库的问题

标签 java android facebook encryption io

我在读取 Conceal 数据时遇到问题。我似乎无法正确完成流式传输。 我假装 Conceal 有一些问题,因为当我切换我的 proxyStream (只是加密部分)不通过 Conceal 运行它时,一切都按预期工作。我还假设写入没问题,没有任何异常,我可以在磁盘上找到加密文件。

我通过 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 之间的管道。输入流来自 hide,它是一个包装在 BufferedInputStream 中的 FileInputstream。

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)。你知道可能是什么问题吗?它指向 native 调用,我迷失在其中......

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)

编辑: 看起来流工作正常,但失败的是从中读取的最后一次迭代。当我使用缓冲区时,似乎缓冲区比重新修复数据量大是导致问题的原因。我一直在研究 Conceal 的来源,从这方面来看似乎没问题。难道它不会在 native 层的某个地方失败吗? 注意:我已经成功获取了解密的文件,除了最后的字节 block 之外。所以我有一个不完整的图像文件(最后几千个像素没有显示)

最佳答案

根据我对 Conceal 的一点经验,我注意到,只有加密文件的同一应用程序才能成功解密它,无论它是否具有相同的包。请务必牢记这一点

关于java - facebook Conceal 库的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22906953/

相关文章:

ios - 如何为 native iOS 应用程序创建测试用户?

java - 如何编辑 wicket 组件以获取有关流程的信息

java - 删除java中数组列表中最小的2个元素?

java - Java中的Cron Job第六个参数

android - Lollipop 的 backgroundTint 对 Button 没有影响

android - 访问 asp.net 网络服务

iphone - Facebook Graph API(向人们介绍我的应用程序)

java - Liferay MVC Portlet java.lang.ClassNotFoundException

android - Ionic - 启用 GPS

asp.net - 如何为我的网站实现 Facebook "Like"按钮