Class SecureEncodingUtils

java.lang.Object
de.craftsblock.craftsnet.utils.SecureEncodingUtils

public class SecureEncodingUtils extends Object
Utility class for secure encoding and decoding of character arrays to byte arrays and vice versa.

This class provides methods to convert between char[] and byte[] while minimizing sensitive data retention in memory by clearing intermediate buffers after use.

Since:
3.4.1-SNAPSHOT
  • Method Details

    • encode

      public static byte[] encode(char @NotNull [] chars, @NotNull @NotNull Charset charset)
      Encodes a given array of chars into a byte array.
      Parameters:
      chars - The input character array to encode
      charset - The charset to use for encoding; must not be null
      Returns:
      A byte array containing the bytes of the input characters
      Throws:
      RuntimeException - If the encoding fails
    • decode

      public static char[] decode(byte @NotNull [] bytes, @NotNull @NotNull Charset charset)
      Decodes the given byte array into a char array using the specified charset.
      Parameters:
      bytes - The byte array containing the encoded characters; must not be null
      charset - The charset to use for decoding; must not be null
      Returns:
      A char array containing the decoded characters
      Throws:
      RuntimeException - If decoding fails for any reason
      NullPointerException - If bytes or charset is null