【发布时间】:2016-11-27 06:08:04
【问题描述】:
我正在使用使用 RSA 密钥/对的标准技术,其公钥加密一个 16 字节随机密钥,该密钥使用 AES/CBC/PKCS5Padding 加密我的数据。
我正在使用充气城堡来满足我的需要我需要加密通常是大数据流 (512MB+)。
在运行性能测试以了解加密的开销时,我发现加密比未加密的数据贵近 30-40%。
这是预期的吗?
示例代码
public InputStream encryptStream(InputStream streamToEncrypt, byte[] key, byte[] iv, byte[] encryptedKey // 256 bytes) {
final Cipher cipher = getCipher(Cipher.ENCRYPT_MODE, key, iv);
byte[] civ = cipher.getIV();
...
ByteArrayInputStream ivEncryptedKeyStream = new ByteArrayInputStream(ivEncryptedKeyArray);
CipherInputStream encrypted = new CipherInputStream(streamToEncrypt, cipher);
return new SequenceInputStream(ivEncryptedKeyStream, encrypted);
}
别处
InputStream encryptedStream = ...encryptStream(plainStream, key, iv, encKey);
IOUtils.copyLarge(encryptedStream, outputStream);
我玩过 java server args ;确认 AES-NI 指令集已开启等。 只是想知道加密大型流的开销是多少?
编辑:更正了我仅将 bouncycastle 用于密钥对生成的信息。对于使用 SunJCE 作为安全提供程序的 AES 加密。
【问题讨论】:
-
您是否检查过您的 Java 版本是否使用 AES-NI?见AES-NI intrinsics enabled by default?
-
谢谢。我已经尝试过使用这些参数,并且还添加了 -server 参数,发现性能略有提高。我也会对此进行更多研究。
标签: java security encryption aes