Class StringUtils


  • public class StringUtils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String addColTags​(java.lang.String text)
      Wraps the provided text in a standard color tag <col=ff9040>.
      static java.lang.String decrypt​(java.lang.String base64IvAndCiphertext, java.lang.String key)
      Decrypts a Base64 encoded string containing an IV and ciphertext.
      static java.lang.String encrypt​(java.lang.String plaintext, java.lang.String key)
      Encrypts the given plaintext using AES/CBC/PKCS5Padding.
      static int getIndex​(java.lang.String[] terms, java.lang.String term)
      Finds the index of a term in an array of terms, ignoring case.
      static java.lang.String stripColTags​(java.lang.String source)
      Strips <col=...> tags from a single string.
      static java.lang.String[] stripColTags​(java.lang.String[] sourceList)
      Strips <col=...> tags from each string in the provided array.
      • Methods inherited from class java.lang.Object

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

      • StringUtils

        public StringUtils()
    • Method Detail

      • getIndex

        public static int getIndex​(java.lang.String[] terms,
                                   java.lang.String term)
        Finds the index of a term in an array of terms, ignoring case.
        Parameters:
        terms - the array of terms to search
        term - the term to find
        Returns:
        the index of the term in the array, or -1 if not found
      • stripColTags

        public static java.lang.String[] stripColTags​(java.lang.String[] sourceList)
        Strips <col=...> tags from each string in the provided array.
        Parameters:
        sourceList - the array of strings to process
        Returns:
        a new array with <col=...> tags removed
      • stripColTags

        public static java.lang.String stripColTags​(java.lang.String source)
        Strips <col=...> tags from a single string.
        Parameters:
        source - the string to process
        Returns:
        the string with all color tags removed
      • addColTags

        public static java.lang.String addColTags​(java.lang.String text)
        Wraps the provided text in a standard color tag <col=ff9040>.
        Parameters:
        text - the text to wrap
        Returns:
        the text wrapped in color tags, or the original text if null or empty
      • encrypt

        public static java.lang.String encrypt​(java.lang.String plaintext,
                                               java.lang.String key)
        Encrypts the given plaintext using AES/CBC/PKCS5Padding.

        This method generates a random 16-byte IV, performs the encryption, combines the IV and the ciphertext, and returns the result as a Base64 encoded string.

        Parameters:
        plaintext - the text to encrypt
        key - A 32 byte base64 encoded key used to encrypt the string
        Returns:
        a Base64 encoded string containing the IV followed by the encrypted bytes
        Throws:
        java.lang.RuntimeException - if the encryption process fails
      • decrypt

        public static java.lang.String decrypt​(java.lang.String base64IvAndCiphertext,
                                               java.lang.String key)
        Decrypts a Base64 encoded string containing an IV and ciphertext.

        This method expects the input string to be the result of the encrypt(String, String) method. It extracts the IV from the first 16 bytes and decrypts the remaining bytes.

        Parameters:
        base64IvAndCiphertext - the Base64 encoded string containing the IV and encrypted data
        key - a 32 byte base64 encoded key for decrypting the string.
        Returns:
        the decrypted plaintext string
        Throws:
        java.lang.RuntimeException - if the decryption process fails