我有這個代碼來加密視頻文件。加速加密?
public static void encryptVideos(File fil,File outfile)
{
try{
FileInputStream fis = new FileInputStream(fil);
//File outfile = new File(fil2);
int read;
if(!outfile.exists())
outfile.createNewFile();
FileOutputStream fos = new FileOutputStream(outfile);
FileInputStream encfis = new FileInputStream(outfile);
Cipher encipher = Cipher.getInstance("AES");
KeyGenerator kgen = KeyGenerator.getInstance("AES");
//byte key[] = {0x00,0x32,0x22,0x11,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
SecretKey skey = kgen.generateKey();
//Lgo
encipher.init(Cipher.ENCRYPT_MODE, skey);
CipherInputStream cis = new CipherInputStream(fis, encipher);
while((read = cis.read())!=-1)
{
fos.write(read);
fos.flush();
}
fos.close();
}catch (Exception e) {
// TODO: handle exception
}
}
但我使用的文件非常大,使用這種方法需要很多時間。 我該如何加快速度?
Encyrption是資源密集型的。整個想法是,你正在以一種複雜的方式破壞內容。 – mcfinnigan 2012-02-29 11:08:54
你得到什麼樣的速度?你有沒有嘗試*映射*文件,並在ByteBuffer的返回(ps不知道,如果這可能爲android,忽略標籤)執行加密? – 2012-03-01 00:45:26
我是新手我不知道它的可能 – Navdroid 2012-03-01 05:19:46