• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Video Encryption Decryption takes too much time

SnehalD

Lurker
Aug 11, 2018
1
0
This is code for encryption of video


FileInputStream fis = new FileInputStream(extStore+"/digilearn/try.mp4");
FileOutputStream fos = new FileOutputStream(extStore+"/digilearn/enctry.mp4");
SecretKeySpec sks = new SecretKeySpec("MyDifficultPassw".getBytes(),
"AES");

Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, sks);

CipherOutputStream cos = new CipherOutputStream(fos, cipher);
int b;
byte[] d = new byte[8192];
while ((b = fis.read(d)) != -1) {
cos.write(d, 0, b);
}
// Flush and close streams.
cos.flush();
cos.close();
fis.close();


This is the code for decryption of video

File extStore = Environment.getExternalStorageDirectory();
FileInputStream fis = new FileInputStream(extStore+"/digilearn/enctry.mp4");

FileOutputStream fos = new FileOutputStream(extStore+"/digilearn/dectry.mp4");
SecretKeySpec sks = new SecretKeySpec("MyDifficultPassw".getBytes(),
"AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, sks);
CipherInputStream cis = new CipherInputStream(fis, cipher);
int b;
byte[] d = new byte[2*8192];
while ((b = cis.read(d)) != -1) {
fos.write(d, 0, b);
}
fos.flush();
fos.close();
cis.close();



with above code encryption and decryption both works but it take too much time when encrypted video file from sd card with video size is 1 GB.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones