簡體   English   中英

Facebook隱藏庫的問題

[英]Problems with facebooks conceal library

我從隱藏中讀取解密的數據時遇到問題。 看來我無法正確完成流式傳輸。 我假裝有一些隱藏問題,因為當我切換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團隊中,可能寧願使用帶有在MediaStore.MediaColumns()發送的字節數組的標准query()方法,這不適合我,因為我不僅要加密媒體文件,而且我也喜歡流的方法更好。

這就是我從Inpustream閱讀的方式。 它基本上是兩個parcelFileDescriptor之間的管道。 inputstream來自隱藏,它是一個包裝在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 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()。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM