【问题标题】:Decrypting AES encrypted .ts files [closed]解密 AES 加密的 .ts 文件 [关闭]
【发布时间】:2013-01-12 02:51:13
【问题描述】:

我想在 Android 中使用 AES 128 位加密简单地解密加密的 ts 文件。 我知道如果我玩 m3u8,那么 Player 可以解决这个问题,但我想直接访问 ts 并想单独播放,所以需要在播放前对其进行解密。

让我知道适用的 Java 类。

【问题讨论】:

  • 所以这意味着我以后不能因为我过去的错误而提问?
  • 不,这意味着不会鼓励人们帮助你。
  • 这里有一些类似的问题stackoverflow.com/questions/6557909/… 那么这是如何被接受的呢?接受与否,这只是人们的心态..
  • @PGU:第一:它已经有 3 票接近。而且,到目前为止还没有答案。 第二:仅仅因为没有注意到其他问题并不能使它们正确。

标签: android http-streaming


【解决方案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();
    }
}

&lt;&gt; 之间的所有内容替换为适合您文件的内容,然后就可以开始了。

【讨论】:

  • 感谢 sn-p。我确实有用于 AES 的 IV,所以可以用作密钥?我是 AES 新手,所以请告诉我。
猜你喜欢
  • 1970-01-01
  • 2021-11-23
  • 2018-10-08
  • 1970-01-01
  • 2015-05-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-30
  • 2012-02-18
相关资源
最近更新 更多