Package org.apereo.cas.util.gen
Class AbstractRandomStringGenerator
- java.lang.Object
-
- org.apereo.cas.util.gen.AbstractRandomStringGenerator
-
- All Implemented Interfaces:
RandomStringGenerator
- Direct Known Subclasses:
Base64RandomStringGenerator,DefaultRandomStringGenerator,HexRandomStringGenerator
public abstract class AbstractRandomStringGenerator extends java.lang.Object implements RandomStringGenerator
This isAbstractRandomStringGenerator.Implementation of the RandomStringGenerator that allows you to define the length of the random part.
- Since:
- 5.2.0
-
-
Field Summary
Fields Modifier and Type Field Description protected longdefaultLengthDefault string length before encoding.protected java.security.SecureRandomrandomizerAn instance of secure random to ensure randomness is secure.-
Fields inherited from interface org.apereo.cas.util.gen.RandomStringGenerator
DEFAULT_LENGTH
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractRandomStringGenerator()Instantiates a new default random string generator with length set toRandomStringGenerator.DEFAULT_LENGTH.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringconvertBytesToString(byte[] random)Converts byte[] to String by simple cast.java.lang.StringgetAlgorithm()The algorithm used by the generator's SecureRandom instance.java.lang.StringgetNewString()A new random string of specified default size.java.lang.StringgetNewString(int size)A new random string of specified initial size.byte[]getNewStringAsBytes(int size)Gets the new string as bytes.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apereo.cas.util.gen.RandomStringGenerator
getDefaultLength
-
-
-
-
Constructor Detail
-
AbstractRandomStringGenerator
protected AbstractRandomStringGenerator()
Instantiates a new default random string generator with length set toRandomStringGenerator.DEFAULT_LENGTH.
-
-
Method Detail
-
getAlgorithm
public java.lang.String getAlgorithm()
Description copied from interface:RandomStringGeneratorThe algorithm used by the generator's SecureRandom instance.- Specified by:
getAlgorithmin interfaceRandomStringGenerator- Returns:
- the algorithm used by the generator's SecureRandom instance.
-
convertBytesToString
protected java.lang.String convertBytesToString(byte[] random)
Converts byte[] to String by simple cast. Subclasses should override.- Parameters:
random- raw bytes- Returns:
- a converted String
-
getNewString
public java.lang.String getNewString(int size)
Description copied from interface:RandomStringGeneratorA new random string of specified initial size.- Specified by:
getNewStringin interfaceRandomStringGenerator- Parameters:
size- length of random string before encoding- Returns:
- a new random string of specified initial size
-
getNewString
public java.lang.String getNewString()
Description copied from interface:RandomStringGeneratorA new random string of specified default size.- Specified by:
getNewStringin interfaceRandomStringGenerator- Returns:
- a new random string of default initial size
-
getNewStringAsBytes
public byte[] getNewStringAsBytes(int size)
Description copied from interface:RandomStringGeneratorGets the new string as bytes.- Specified by:
getNewStringAsBytesin interfaceRandomStringGenerator- Parameters:
size- the size of return- Returns:
- the new random string as bytes
-
-