Java SecureRandom.setSeed(byte[] seed)

Syntax

SecureRandom.setSeed(byte[] seed) has the following syntax.

public void setSeed(byte[] seed)

Example

In the following code shows how to use SecureRandom.setSeed(byte[] seed) method.


//from  w w w  .ja va2s  .  c  o m

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();


    SecureRandom srand = SecureRandom.getInstance("SHA1PRNG");
    srand.setSeed(new byte[]{1,2,3,4});
    byte[] bytes = new byte[numBytes];
    srand.nextBytes(bytes);
    System.out.println(new String(bytes));
  }
}




















Home »
  Java Tutorial »
    java.security »




SecureRandom