0

入力ファイルを暗号化するアプリケーションを開発しています。
私のコードはファイルを暗号化するためのものです(ファイルサイズは数KBから4GBまで異なります):

    SecretKeySpec   key = new SecretKeySpec(keyBytes, "AES");
    IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
    Cipher          cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
    byte[] block = new byte[8];
    int i;

    cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec);

    BufferedInputStream bIn=new BufferedInputStream(new ProgressMonitorInputStream(null,"Encrypting ...",new FileInputStream("input")));
    CipherInputStream       cIn = new CipherInputStream(bIn, cipher);
    BufferedOutputStream bOut=new BufferedOutputStream(new FileOutputStream("output.enc"));

    int ch;
    while ((i = cIn.read(block)) != -1) {
        bOut.write(block, 0, i);
    }
    cIn.close();
    bOut.close();

より最適化できますか (時間、IO、CPU)?
どのように?

ありがとう

4

3 に答える 3

2

これは複雑で答えるのが難しい質問です。まず、4GB相当のファイルの暗号化には、何をしても時間がかかります。

Hummingbirdのような軽量の暗号化アルゴリズムは、そこに到達するのに役立ちますが、これを使用している場所では、AESが絶対に必要なわけではないことを確認する必要があります。

于 2012-08-31T19:35:57.393 に答える
1

より適切なbyte[] blockサイズを選択すると役立ちます(8kから1MBの範囲で、シナリオに最適なサイズを見つけるためにテストします)が、それ以外に、高速化するためにできることはあまりありません(現在の暗号化アルゴリズムを維持していると仮定します)。

于 2012-08-31T19:58:11.377 に答える
1

What you can do is to you use AESFastEngine from bouncycastle library to accelerate aes block computation.

crypto/src/org/bouncycastle/crypto/engines

This fast engine uses T tables which are rounded precomputed table and for sure will have a gain in performance.

于 2012-09-03T08:21:28.907 に答える