How to generate a secure random alphanumeric string in Java efficiently?

后端 未结 9 1500
半阙折子戏
半阙折子戏 2021-01-01 12:24

How do you generate a secure random (or pseudo-random) alphanumeric string in Java efficiently?

9条回答
  •  不知归路
    2021-01-01 13:02

    http://download.oracle.com/javase/6/docs/api/java/security/SecureRandom.html

    From the Javadoc:

    SecureRandom random = new SecureRandom();
    byte bytes[] = new byte[20];
    random.nextBytes(bytes);
    

提交回复
热议问题