Class SecretGenerator

java.lang.Object
org.keycloak.common.util.SecretGenerator

public class SecretGenerator extends Object
  • Field Details

    • SECRET_LENGTH_256_BITS

      public static final int SECRET_LENGTH_256_BITS
      See Also:
    • SECRET_LENGTH_384_BITS

      public static final int SECRET_LENGTH_384_BITS
      See Also:
    • SECRET_LENGTH_512_BITS

      public static final int SECRET_LENGTH_512_BITS
      See Also:
    • UPPER

      public static final char[] UPPER
    • DIGITS

      public static final char[] DIGITS
    • ALPHANUM

      public static final char[] ALPHANUM
  • Method Details

    • getInstance

      public static SecretGenerator getInstance()
    • randomString

      public String randomString()
    • randomString

      public String randomString(int length)
    • randomString

      public String randomString(int length, char[] symbols)
    • randomBytes

      public byte[] randomBytes()
    • randomBytes

      public byte[] randomBytes(int length)
    • equivalentEntropySize

      public static int equivalentEntropySize(int byteLengthEntropy, int dstAlphabetLeng)
      Returns the equivalent length for a destination alphabet to have the same entropy bits than a byte array random generated.
      Parameters:
      byteLengthEntropy - The desired entropy in bytes
      dstAlphabetLeng - The length of the destination alphabet
      Returns:
      The equivalent length in destination alphabet to have the same entropy bits
    • equivalentEntropySize

      public static int equivalentEntropySize(int length, int srcAlphabetLength, int dstAlphabetLeng)
      Returns the equivalent length for a destination alphabet to have the same entropy bits than another source alphabet.
      Parameters:
      length - The length of the string encoded in source alphabet
      srcAlphabetLength - The length of the source alphabet
      dstAlphabetLeng - The length of the destination alphabet
      Returns:
      The equivalent length (same entropy) in destination alphabet for a string of length in source alphabet