I have an encryption and decryption code that I use to encrypt and decrypt video files (mp4). I am trying to speed up the decryption process because encryption is not suitable for my business. This is the code I have for the decryption process:
private static void decryptFile() throws IOException, ShortBufferException, IllegalBlockSizeException, BadPaddingException
{
int blockSize = cipher.getBlockSize();
int outputSize = cipher.getOutputSize(blockSize);
System.out.println("outputsize: " + outputSize);
byte[] inBytes = new byte[blockSize];
byte[] outBytes = new byte[outputSize];
in= new FileInputStream(inputFile);
out=new FileOutputStream(outputFile);
BufferedInputStream inStream = new BufferedInputStream(in);
int inLength = 0;;
boolean more = true;
while (more)
{
inLength = inStream.read(inBytes);
if (inLength == blockSize)
{
int outLength
= cipher.update(inBytes, 0, blockSize, outBytes);
out.write(outBytes, 0, outLength);
}
else more = false;
}
if (inLength > 0)
outBytes = cipher.doFinal(inBytes, 0, inLength);
else
outBytes = cipher.doFinal();
out.write(outBytes);
}
My question is how to speed up the decryption process in this code. I tried to decrypt a 10 MB mp4 file and it decrypts in 6-7 seconds. However, I aim for <1 second. Another thing I would like to know is that writing to FileOutputStream actually slows down the process, not the decryption process itself. Any suggestions on how to speed things up here.
I use AES for encryption / decryption.
, ProgressDialog, , (, : decrypted).