The difference between random and urandom on Linux

项目使用AES加密,结果WIN下一切正常,但是Linux下每次密文都不同。

 

kgen = KeyGenerator.getInstance("AES");
kgen.init(128, new SecureRandom(key.getBytes()));

 

http://forums.sun.com/thread.jspa?threadID=5298375

 

the key:

 

 * By default Linux/Solaris are using NativePRNG algorithm
 * under Java5 which is incomparable with SecureRandom generation
 * used in this code.
 
 * Windows Java5 as well as Windows and Linux/Solaris under Java 1.4
 * are using SHA1PRNG SecureRandom algorithm.
 * 
 * To fix this issue and force Java5 under Linux/Solaris uses SHA1PRNG
 * instead of NativePRNG do the following:
 * 
 * edit the file java.security located at
 * <your java installation directory>/jre/lib/security/java.security
 * 
 * find the line:
 * securerandom.source=file:/dev/urandom
 * commet it out and insert the new line
 * securerandom.source=file:/dev/random



When read, the /dev/random device will only
return random bytes within the estimated number of bits of noise in the
entropy pool. /dev/random >should be suitable for uses that need
very high quality randomness such as one-time pad or key generation.
When the entropy pool is empty, reads >from /dev/random will block
until additional environmental noise is gathered.

A read from the /dev/urandom device will not block waiting for more entropy. As a result, if there is not sufficient entropy in the entropy pool, the >returned values are theoretically vulnerable to a cryptographic attack on the algorithms used by the driver. Knowledge of how to do this is not available >in the current non-classified literature, but it is theoretically possible that such an attack may exist. If this is a concern in your application, use >/dev/random instead.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值