List of usage examples for java.security SecureRandom nextBytes
@Override public void nextBytes(byte[] bytes)
From source file:Main.java
public static void main(String[] argv) throws Exception { SecureRandom sr = new SecureRandom(); byte[] bytes = new byte[8]; sr.nextBytes(bytes); System.out.println(Arrays.toString(bytes)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); byte[] bytes = new byte[8]; sr.nextBytes(bytes); System.out.println(Arrays.toString(bytes)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); byte[] bytes = new byte[1024 / 8]; sr.nextBytes(bytes); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { SecureRandom random = new SecureRandom(); byte[] keyBytes = new byte[20]; random.nextBytes(keyBytes); SecretKeySpec key = new SecretKeySpec(keyBytes, "HMACSHA1"); System.out.println("Key:" + new BASE64Encoder().encode(key.getEncoded())); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(key);/*from w w w . j a va 2 s .c o m*/ mac.update("test".getBytes("UTF8")); byte[] result = mac.doFinal(); System.out.println("MAC: " + new BASE64Encoder().encode(result)); }
From source file:Main.java
public static void main(String[] args) throws NoSuchAlgorithmException { int numBytes = (new Integer("1111")).intValue(); SecureRandom srand = new SecureRandom(new byte[] { 1, 2, 3, 4 }); byte[] bytes = new byte[numBytes]; srand.nextBytes(bytes); System.out.println(new String(bytes)); }
From source file:Main.java
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)); }
From source file:MainClass.java
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);/* ww w. jav a 2 s . c o m*/ byte[] bytes = new byte[numBytes]; srand.nextBytes(bytes); System.out.println(new String(bytes)); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); SecureRandom rng = SecureRandom.getInstance("SHA1PRNG"); rng.setSeed(711);//from w w w.j av a 2s . com int numberToGenerate = 999; byte randNumbers[] = new byte[numberToGenerate]; rng.nextBytes(randNumbers); for (int j = 0; j < numberToGenerate; j++) { System.out.print(randNumbers[j] + " "); } }
From source file:Main.java
public static void main(String[] args) throws NoSuchAlgorithmException { int numBytes = (new Integer("1111")).intValue(); SecureRandom srand = new SecureRandom(new byte[] { 1, 2, 3, 4 }); Provider provider = srand.getProvider(); System.out.println(provider.getName()); byte[] bytes = new byte[numBytes]; srand.nextBytes(bytes); System.out.println(bytes);//from www. ja v a2s . c o m }
From source file:Main.java
public static void main(String[] args) throws NoSuchAlgorithmException { int numBytes = (new Integer("1111")).intValue(); SecureRandom srand = new SecureRandom(new byte[] { 1, 2, 3, 4 }); Provider provider = srand.getProvider(); SecureRandom newRandom = SecureRandom.getInstance("SHA1PRNG", provider); System.out.println(provider.getName()); byte[] bytes = new byte[numBytes]; srand.nextBytes(bytes); System.out.println(bytes);//from w w w .j ava2 s . c o m }