code: public static byte[] toBytes(final char[] chars, final String encoding) {
  
          Validate.notBlank(encoding, "The validated character sequence 'encoding' is null or empty");
  
          // make sure we can handle null inputs, and create a defensive copy of the input if needed
          char[] myChars;
          if (chars == null) {
              myChars = new char[0];
          } else {
              myChars = Arrays.copyOf(chars, chars.length);
          }
  
          // conversion
          final Charset charset = Charset.forName(encoding);
          final CharBuffer charBuffer = CharBuffer.wrap(myChars);
          final ByteBuffer byteBuffer = charset.encode(charBuffer);
          final byte[] result = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit());
  
          // clear confidential data from the array backing the byte buffer
          // there is no need to clear the array in the char buffer, because we simply wrapped the original array, and
          // did not copy it. The caller has to clear that array if they want to wipe any confidential data in the array.
          Cleanser.wipe(byteBuffer.array());
  
          return result;
      }
docs: Convert a char array to a byte array using the provided String encoding.
  <p>
  Note that this method does not change the provided source array.
  
  @param chars    The char array to convert
  @param encoding The string encoding to use
  @return The byte[] representation of the provided char array
  @throws NullPointerException                         When {@code encoding} is null
  @throws IllegalArgumentException                     When {@code encoding} is empty
  @throws java.nio.charset.UnsupportedCharsetException When {@code encoding} is invalid