public static byte[] toBytes(String source, String encoding) throws CodecException {
        try {
            return source.getBytes(encoding);
        } catch (UnsupportedEncodingException e) {
            String msg = "Unable to convert source [" + source + "] to byte array using " +
                    "encoding '" + encoding + "'";
            throw new CodecException(msg, e);
        }
    }
Converts the specified source to a byte array via the specified encoding, throwing a
{@link CodecException CodecException} if the encoding fails.

@param source   the source string to convert to a byte array.
@param encoding the encoding to use to use.
@return the byte array of the specified source with the given encoding.
@throws CodecException if the JVM does not support the specified encoding.
src/main/java/org/apache/shiro/lang/codec/CodecSupport.java