SecureRandom: nextBytes(byte[] bytes) : SecureRandom « java.security « Java by API






SecureRandom: nextBytes(byte[] bytes)

  


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

public class Main {
  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));
  }
}

   
    
  








Related examples in the same category

1.new SecureRandom()
2.SecureRandom: getInstance(String algorithm) throws NoSuchAlgorithmException
3.SecureRandom: setSeed(long seed)