加快加密/解密? [英] Speed up encryption/decryption?

查看:146
本文介绍了加快加密/解密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个加密和解密code,我用它来加密和解密的视频文件(MP4)。我试图加快解密过程加密一个不是说有关我的情况。这是code,我对解密过程:

I have an encryption and decryption code which I use to encrypt and decrypt video files (mp4). I'm trying to speed up the decryption process as the encryption one is not that relevant for my case. This is the code that I have for the decryption process:

private static void  decryptFile() throws IOException, ShortBufferException, IllegalBlockSizeException, BadPaddingException
    {

        //int blockSize = cipher.getBlockSize();
        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);

}

我的问题是如何加快在这一code解密过程。我试图解密一个10MB的MP4文件,并将其解密在6-7秒。然而,我的目标< 1秒。。另一件事我想知道的是,如果我写的FileOutputStream中出实际上是延缓下跌过程,而不是解密过程本身。关于如何去加速的事情在这里的任何建议。

My question is how to speed up the decryption process in this code. I've tried decrypting a 10MB mp4 file and it decrypts in 6-7 seconds. However, I'm aiming for < 1 seconds. Another thing I would like to know is if my writing to the FileOutputStream out is actually slowing the process down rather than the decryption process itself. Any suggestions on how to go about speeding things up here.

编辑:我使用AES加密/解密

I'm using AES for encryption/decryption.

2日编辑:直到我找到一个解决方案,我将使用一个ProgressDialog它告诉用户要等到影片已被解密(显然,我不会使用这个词:解密)。

2nd Until I find a solution, I will be using a ProgressDialog which tells the user to wait until the video has been decrypted (Obviously, I'm not going to use the word: decrypted).

推荐答案

你为什么要解密只能由块大小增量数据?你不显示什么类型的对象密码是的,但我猜这是一个 javax.crypto.Cipher中实例。它可以处理更新()要求在任意长度的数组,你将有更少的开销,如果你使用更长的数组。你应该的,也就是说,8192个字节的块数据处理(这是传统长度的缓冲器,它交互合理地与CPU内部缓存)。

Why are you decrypting data only by blockSize increments ? You do not show what type of object cipher is, but I am guessing this is a javax.crypto.Cipher instance. It can handle update() calls over arrays of arbitrary length, and you will have much less overhead if you use longer arrays. You should process data by blocks of, say, 8192 bytes (that's the traditional length for a buffer, it interacts reasonably well with CPU inner caches).

这篇关于加快加密/解密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆