Class SecureCodes


  • public class SecureCodes
    extends java.lang.Object
    Utility 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
      SecureCode code​(int byteLength)
      Generates a new, random secure code with the specified number of bytes.
      SecureCode code128()
      Generates a new, random secure code with a length of 128 bytes (1024 bit)
      SecureCode code16()
      Generates a new, random secure code with a length of 16 bytes (128 bit)
      SecureCode code24()
      Generates a new, random secure code with a length of 24 bytes (192 bit)
      SecureCode code256()
      Generates a new, random secure code with a length of 256 bytes (2048 bit)
      SecureCode code32()
      Generates a new, random secure code with a length of 32 bytes (256 bit)
      SecureCode code36()
      Generates a new, random secure code with a length of 36 bytes (288 bit)
      SecureCode code48()
      Generates a new, random secure code with a length of 48 bytes (384 bit)
      SecureCode code512()
      Generates a new, random secure code with a length of 512 bytes (4096 bit)
      SecureCode code60()
      Generates a new, random secure code with a length of 60 bytes (480 bit)
      SecureCode code64()
      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.String encode​(byte[] bytes)  
      static SecureCodes getInstance()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SecureCodes

        public SecureCodes()
      • SecureCodes

        public SecureCodes​(java.security.SecureRandom random)
    • 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.IllegalArgumentException
        Decodes 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