我必須閱讀Android設備上的加密視頻。Android上的AES密碼無法讀取crypt視頻
我創建使用http://elonen.iki.fi/code/nanohttpd/本地主機服務器允許這在一個非常簡單的方法。
我用它實現閱讀未加密的影片,但我卡在讀取加密的視頻。 (我沒有任何麻煩加密視頻,只是爲了閱讀)
我試過如下:
1-要使用一個簡單的「AES」加密視頻,當我嘗試閱讀它與我的服務器,我看到流開始(我看到我的服務器回答3次各種範圍)。 經過3次玩家表示無法閱讀視頻。
2到加密使用「AES/CTR/NoPadding」的視頻:在這種情況下,我看到我的服務器一而再,再而再次提供第一範圍和ISS運行,但沒有視頻顯示。
我嘗試用CTR16得到的16位塊,並與32KO的BUFER閱讀。這是行不通的。
(PS:我有uncrypt畫面沒有問題,我的方法)
這裏我隱窩方法:
public static InputStream getUncryptInputStream(InputStream is, String pass, final long dataLen) throws Exception{
SecretKeySpec key = new SecretKeySpec(getRawKey(pass.getBytes()), "AES");
Cipher mCipher = Cipher.getInstance("AES/CTR/NoPadding");
mCipher.init(Cipher.DECRYPT_MODE, key, ivSpec);
if(dataLen==-1){
return new CipherInputStream(is, mCipher);
}else{
return new CipherInputStreamWithDataLen(is, mCipher, dataLen);
}
}
public static OutputStream getCryptOutputStream(OutputStream os, String pass) throws Exception{
SecretKeySpec key = new SecretKeySpec(getRawKey(pass.getBytes()), "AES");
Cipher mCipher = Cipher.getInstance("AES/CTR/NoPadding");
mCipher.init(Cipher.ENCRYPT_MODE, key, ivSpec);
return new CipherOutputStream(os, mCipher);
}
private static byte[] getRawKey(byte[] seed) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(seed);
kgen.init(128, sr); // 192 and 256 bits may not be available
SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();
return raw;
}
和我創建,因爲可用的方法總是返回0
與正常CipherInputStreamWithData
的CipherInputStreamWithData
:
import java.io.IOException;
import java.io.InputStream;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
public class CipherInputStreamWithDataLen extends CipherInputStream{
int dataLen;
public CipherInputStreamWithDataLen(InputStream is, Cipher mCipher, long dataLen) {
super(is, mCipher);
this.dataLen = (int)dataLen;
// TODO Auto-generated constructor stub
}
public int available() throws IOException{
return dataLen;
}
}
問題來自CipherInputStream。 – Yop 2012-07-24 12:25:16