Secure Random Demo : Secure Random « Security « Java Tutorial






import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

public class MainClass {
  public static void main(String[] args) throws NoSuchAlgorithmException {
    int numBytes = (new Integer("1111")).intValue();
    long seed = 01;
    if (args.length > 1)
      seed = (new Long("1111111111")).longValue();
    SecureRandom srand = SecureRandom.getInstance("SHA1PRNG");
    if (seed != 01)
      srand.setSeed(seed);
    byte[] bytes = new byte[numBytes];
    srand.nextBytes(bytes);
    System.out.println(new String(bytes));
  }
}








36.40.Secure Random
36.40.1.Secure Random Demo
36.40.2.Generating a Secure Random Number
36.40.3.Seed a Secure Random