Package com.fizzed.crux.util
Class SecureCodes
- java.lang.Object
-
- com.fizzed.crux.util.SecureCodes
-
public class SecureCodes extends java.lang.ObjectUtility class for generating and handling SecureCodes. A SecureCode is efficiently stored as bytes with an external base64, URL-safe string representation. The base64 padding chars will be removed too.
-
-
Constructor Summary
Constructors Constructor Description SecureCodes()SecureCodes(java.security.SecureRandom random)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SecureCodecode(int byteLength)Generates a new, random secure code with the specified number of bytes.SecureCodecode128()Generates a new, random secure code with a length of 128 bytes (1024 bit)SecureCodecode16()Generates a new, random secure code with a length of 16 bytes (128 bit)SecureCodecode24()Generates a new, random secure code with a length of 24 bytes (192 bit)SecureCodecode256()Generates a new, random secure code with a length of 256 bytes (2048 bit)SecureCodecode32()Generates a new, random secure code with a length of 32 bytes (256 bit)SecureCodecode36()Generates a new, random secure code with a length of 36 bytes (288 bit)SecureCodecode48()Generates a new, random secure code with a length of 48 bytes (384 bit)SecureCodecode512()Generates a new, random secure code with a length of 512 bytes (4096 bit)SecureCodecode60()Generates a new, random secure code with a length of 60 bytes (480 bit)SecureCodecode64()Generates a new, random secure code with a length of 64 bytes (512 bit)static byte[]decode(java.lang.String string)Decodes a secure code external representation.static java.lang.Stringencode(byte[] bytes)static SecureCodesgetInstance()
-
-
-
Method Detail
-
getInstance
public static SecureCodes getInstance()
-
code
public SecureCode code(int byteLength)
Generates a new, random secure code with the specified number of bytes.- Parameters:
byteLength- The number of bytes to randomly generate- Returns:
- A new, randomly generated secure code
-
code16
public SecureCode code16()
Generates a new, random secure code with a length of 16 bytes (128 bit)- Returns:
- A new, randomly generated 16 byte (128 bit) secure code
-
code24
public SecureCode code24()
Generates a new, random secure code with a length of 24 bytes (192 bit)- Returns:
- A new, randomly generated 24 byte (192 bit) secure code
-
code32
public SecureCode code32()
Generates a new, random secure code with a length of 32 bytes (256 bit)- Returns:
- A new, randomly generated 32 byte (256 bit) secure code
-
code36
public SecureCode code36()
Generates a new, random secure code with a length of 36 bytes (288 bit)- Returns:
- A new, randomly generated 36 byte (288 bit) secure code
-
code48
public SecureCode code48()
Generates a new, random secure code with a length of 48 bytes (384 bit)- Returns:
- A new, randomly generated 48 byte (384 bit) secure code
-
code60
public SecureCode code60()
Generates a new, random secure code with a length of 60 bytes (480 bit)- Returns:
- A new, randomly generated 60 byte (480 bit) secure code
-
code64
public SecureCode code64()
Generates a new, random secure code with a length of 64 bytes (512 bit)- Returns:
- A new, randomly generated 64 byte (512 bit) secure code
-
code128
public SecureCode code128()
Generates a new, random secure code with a length of 128 bytes (1024 bit)- Returns:
- A new, randomly generated 128 byte (1024 bit) secure code
-
code256
public SecureCode code256()
Generates a new, random secure code with a length of 256 bytes (2048 bit)- Returns:
- A new, randomly generated 256 byte (2048 bit) secure code
-
code512
public SecureCode code512()
Generates a new, random secure code with a length of 512 bytes (4096 bit)- Returns:
- A new, randomly generated 512 byte (4096 bit) secure code
-
encode
public static java.lang.String encode(byte[] bytes)
-
decode
public static byte[] decode(java.lang.String string) throws java.lang.IllegalArgumentExceptionDecodes a secure code external representation.- Parameters:
string- The external string- Returns:
- The byte array
- Throws:
java.lang.IllegalArgumentException- If the value is detected to be invalid
-
-