Fortify 漏洞 由 nextInt() 实施的随机数生成器不能抵挡加密攻击

亲测可用:

/**
 * 随机数生成
 * @param seed
 * @return
 */
public static int nextInt(int seed){
   return new SecureRandomTest().getRandom(seed);
}

/**
 * 随机数生成
 * @return
 */
public static int nextInt(){
   return new SecureRandomTest().getRandom();
}

public static class SecureRandomTest {
   private static SecureRandom ran;

   public SecureRandomTest(){
      ran = new SecureRandom();
   }
   public int getRandom(int seed) {
      return ran.nextInt(seed);
   }
   public int getRandom() {
      return ran.nextInt();
   }
}

你可能感兴趣的:(Fortify)