1

我試圖通過使用隱藏(facebook)來解密bytearray。java.io.IOException:意外的加密版本0

我的代碼如下

Log.d("Esource", " intial buffer size = " + buffer.length); 
    Crypto crypto = new Crypto(new SharedPrefsBackedKeyChain(this), new SystemNativeCryptoLibrary()); 
    ByteArrayInputStream byteInputStream = new ByteArrayInputStream(buffer); 
    InputStream inputStream = null; 
    try { 
     inputStream = crypto.getCipherInputStream(byteInputStream, new Entity("Password")); 
     Log.d("Esource", "applied decryption "); 
    } catch (CryptoInitializationException e) { 
     Log.d("Esource", "applied decryption e = " + e.getMessage()); 
     e.printStackTrace(); 
    } catch (KeyChainException e) { 
     Log.d("Esource", "applied decryption e = " + e.getMessage()); 
     e.printStackTrace(); 
    } catch (Exception e) { 
     Log.d("ESource", "applied decryption e = " + e.getMessage()); 
     e.printStackTrace(); 
    } 

    ByteArrayOutputStream out = new ByteArrayOutputStream(); 

    int read; 
    byte[] dBuffer = new byte[readLength]; 
    if (inputStream != null) { 
     while ((read = inputStream.read(dBuffer)) != -1) { 
      out.write(dBuffer, 0, read); 
     } 
    } else 
     Log.d("Esource", "inputSTream after cipher is null"); 
    buffer = out.toByteArray(); 

我得到以下錯誤

ava.io.IOException: Unexpected crypto version 0 
at com.facebook.crypto.util.Assertions.checkArgumentForIO(Assertions.java:29) 
at com.facebook.crypto.CipherHelper.getCipherInputStream(CipherHelper.java:52) 
at com.facebook.crypto.Crypto.getCipherInputStream(Crypto.java:83) 
at com.exoplayer.EncryptedDataSource.read(EncryptedDataSource.java:186) 
at  com.google.android.exoplayer.extractor.DefaultExtractorInput.peekFully(DefaultExtractorInput.java:135) 
at com.google.android.exoplayer.extractor.webm.Sniffer.sniff(Sniffer.java:52) 
at com.google.android.exoplayer.extractor.webm.WebmExtractor.sniff(WebmExtractor.java:258) 
at com.google.android.exoplayer.extractor.ExtractorSampleSource$ExtractorHolder.selectExtractor(ExtractorSampleSource.java:805) 
at com.google.android.exoplayer.extractor.ExtractorSampleSource$ExtractingLoadable.load(ExtractorSampleSource.java:746) 
at com.google.android.exoplayer.upstream.Loader$LoadTask.run(Loader.java:209) 
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at java.u 

什麼我做錯了,而decryption.I我因爲最後一天卡住。請幫忙。 在此先感謝。

+0

任何人都可以幫助解決這個問題。我仍然堅持這個問題:( – SimpleCoder

+0

你能解決這個「意想不到的加密版本」的錯誤? – prateek

+0

我得到'意外的加密版本-1' – Pitel

回答

1

您正試圖在寫入任何內容之前從文件讀取加密數據。 嘗試事先寫入數據。 來自conceal github頁面:

// Creates a new Crypto object with default implementations of a key chain 
KeyChain keyChain = new SharedPrefsBackedKeyChain(context, CryptoConfig.KEY_256); 
Crypto crypto = AndroidConceal.get().createDefaultCrypto(keyChain); 

// Check for whether the crypto functionality is available 
// This might fail if Android does not load libaries correctly. 
if (!crypto.isAvailable()) { 
    return; 
} 

OutputStream fileStream = new BufferedOutputStream(
    new FileOutputStream(file)); 

// Creates an output stream which encrypts the data as 
// it is written to it and writes it out to the file. 
OutputStream outputStream = crypto.getCipherOutputStream(
    fileStream, 
    Entity.create("entity_id")); 

// Write plaintext to it. 
outputStream.write(plainText); 
outputStream.close(); 
相關問題