Class CryptoRandom

java.lang.Object
br.net.dd.netherwingcore.common.cryptography.CryptoRandom

public final class CryptoRandom extends Object
Utility class for generating cryptographically secure random bytes.
  • Method Details

    • getRandomBytes

      public static void getRandomBytes(byte[] buf)
      Fills the provided byte array with random bytes.
      Parameters:
      buf - the byte array to fill with random bytes
      Throws:
      NullPointerException - if buf is null
    • getRandomBytes

      public static void getRandomBytes(byte[] buf, int len)
      Fills the first len bytes of the provided byte array with random bytes.
      Parameters:
      buf - the byte array to fill with random bytes
      len - the number of random bytes to generate (must be in range [0, buf.length])
      Throws:
      NullPointerException - if buf is null
      IllegalArgumentException - if len is negative or greater than buf.length
    • getRandomBytes

      public static byte[] getRandomBytes(int size)
      Generates a new byte array of the specified size filled with random bytes.
      Parameters:
      size - the size of the byte array to generate (must be >= 0)
      Returns:
      a new byte array filled with random bytes
      Throws:
      IllegalArgumentException - if size is negative