2013-01-12 428 views
-5

我想在Android中使用AES 128位加密簡單解密加密的ts文件。 我知道,如果我玩m3u8,那麼Player可以照顧這個,但我希望直接訪問ts,並希望單獨播放這些,因此需要在播放之前解密它。解密AES加密.ts文件

讓我知道適用於相同的Java類。

+0

所以這意味着我不能在將來因爲我過去的錯誤而提問? – PGU

+0

不,這意味着人們不會被鼓勵來幫助你。 –

+0

那麼爲什麼要再次投票呢? – PGU

回答

1

假設你知道這是用於對文件進行加密密鑰,您可以使用以下命令:

public static void decrypt() { 
    try { 
     Log.d(C.TAG, "Decrypt Started"); 

     byte[] bytes = new BigInteger(<your key>, 16).toByteArray(); 

     FileInputStream fis = new FileInputStream(<location of encrypted file>); 

     FileOutputStream fos = new FileOutputStream(<location of decrypted file>); 
     SecretKeySpec sks = new SecretKeySpec(bytes, <encryption type>); 
     Cipher cipher = Cipher.getInstance(<encryption type>); 
     cipher.init(Cipher.DECRYPT_MODE, sks); 
     CipherInputStream cis = new CipherInputStream(fis, cipher); 
     int b; 
     byte[] d = new byte[8]; 
     while ((b = cis.read(d)) != -1) { 
      fos.write(d, 0, b); 
     } 
     fos.flush(); 
     fos.close(); 
     cis.close(); 
     Log.d(C.TAG, "Decrypt Ended"); 
    } catch (NoSuchAlgorithmException e) { 
     Log.d(C.TAG, "NoSuchAlgorithmException"); 
     e.printStackTrace(); 
    } catch (InvalidKeyException e) { 
     Log.d(C.TAG, "InvalidKeyException"); 
     e.printStackTrace(); 
    } catch (IOException e) { 
     Log.d(C.TAG, "IOException"); 
     e.printStackTrace(); 
    } catch (NoSuchPaddingException e) { 
     Log.d(C.TAG, "NoSuchPaddingException"); 
     e.printStackTrace(); 
    } 
} 

<>爲您的文件中的相應事物之間更換的一切,你是好走。

+0

謝謝你的代碼片段。我對AES有IV,所以可以用作Key嗎?我是AES新手,請告訴我。 – PGU