简体   繁体   English

Jasypt在Ubuntu Linux上不一致,缓慢的加密性能

[英]Inconsistent, Slow Encryption Performance with Jasypt on Ubuntu Linux

I am using Jasypt's BasicBinaryEncryptor to encrypt small amounts of binary data (around 1 KB). 我正在使用Jasypt的BasicBinaryEncryptor加密少量的二进制数据(大约1 KB)。 I am using Scala, but I doubt that matters. 我正在使用Scala,但我怀疑这很重要。

val encryptor = new BasicBinaryEncryptor
encryptor.setPassword(password)
val encrypted = encryptor.encrypt(bytes.toByteArray())

This encrypt operation can range anywhere from a few seconds, but often runs to over a minute or more. 这种加密操作的范围可以从几秒钟到任何地方,但通常要超过一分钟或更长时间。 It also seems like the first few operations run just fine, but after that it slows down. 似乎前几个操作运行正常,但之后速度变慢。

I have tried Jasypt version 1.9.2 and 1.9.1. 我已经尝试过Jasypt版本1.9.2和1.9.1。 This operation is slow on Ubuntu Linux 14.04 (Hotspot JVM 1.8.0_45) and 15.04, but runs just fine on Mac OS X (Hotspot JVM 1.8.0_40-b25). 在Ubuntu Linux 14.04(Hotspot JVM 1.8.0_45)和15.04上,此操作很慢,但在Mac OS X(Hotspot JVM 1.8.0_40-b25)上运行得很好。

Any thoughts on what I can change to improve performance on Ubuntu? 关于可以更改哪些内容以提高Ubuntu的性能有任何想法吗?

The problem your are experiencing is caused by the salt generator used by Jasypt. 您遇到的问题是Jasypt使用的盐生成器引起的。 BasicBinaryEncryptor uses a StandardPBEByteEncryptor with the default configuration for a SaltGenerator . BasicBinaryEncryptor使用StandardPBEByteEncryptor与一个默认配置SaltGenerator This results in the use of RandomSaltGenerator which uses SecureRandom (as of Jasypt v1.9.1). 这导致使用使用SecureRandomRandomSaltGenerator (从Jasypt v1.9.1开始)。 SecureRandom will block if not enough entropy is available, as markspace pointed out. 如标记空间所指出的,如果没有足够的熵,则SecureRandom将阻止。

If you are ok with using /dev/urandom instead of /dev/random you can start your program with -Djava.security.egd=file:/dev/urandom , which will not block. 如果可以使用/dev/urandom而不是/dev/random ,则可以使用-Djava.security.egd=file:/dev/urandom来启动程序,该程序不会阻塞。

Another option would be to configure your own encryptor and use a different SaltGenerator. 另一种选择是配置您自己的加密器并使用其他SaltGenerator。 Jasypt provides some fixed SaltGenerators you can use, or you can roll your own random one that doesn't use SecureRandom. Jasypt提供了一些固定的SaltGenerators可以使用,或者您可以滚动自己的不使用SecureRandom的随机数。

On our Ubuntu server we installed the haveged package via apt-get . 在我们的Ubuntu服务器上,我们通过apt-get安装了haveged软件包。

Read about that more here: http://www.issihosts.com/haveged/ 在此处了解更多信息: http : //www.issihosts.com/haveged/

The package is not installed by default, but generates entropy. 该软件包默认情况下未安装,但会产生熵。 After doing this, we were able to swap back to /dev/random instead of using /dev/urandom . 完成此操作后,我们可以交换回/dev/random而不必使用/dev/urandom

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM