Class SecureRandomStringUtils

java.lang.Object
com.atlassian.crowd.util.SecureRandomStringUtils

public class SecureRandomStringUtils extends Object
Generates random Strings by selecting characters from an alphabet using a cryptographically secure PRNG. Methods on this class are thread-safe.
  • Method Details

    • getInstance

      public static SecureRandomStringUtils getInstance()
      Returns:
      shared instance of SecureRandomStringUtils.
    • randomString

      public String randomString(int length, char[] alphabet)
      Generates a random String by randomly selecting characters from the provided alphabet until the desired length is reached.

      The method for selecting a random character is specified by the implementation.

      Unicode surrogate-pairing is not supported. All the provided characters should be in the Unicode BMP, if you wish to avoid generating Strings with invalid UTF-16 surrogates.

      Parameters:
      length - desired length of random String. Must be positive.
      alphabet - collection of characters to select from. Must contain at least one character.
      Returns:
      String of length length, composed of characters from the supplied alphabet.
    • randomAlphanumericString

      public String randomAlphanumericString(int length)
      Generates a random String by randomly selecting characters from the the alphabet of characters in the range 0-9, A-Z and a-z.

      The method for selecting a random character is specified by the implementation.

      Parameters:
      length - desired length of random String.
      Returns:
      alphanumeric String of length length.
      See Also: