code: public static String extractTargetNameFromType2Message(byte[] msg,
              Integer msgFlags) throws UnsupportedEncodingException {
          // Read the security buffer to determine where the target name
          // is stored and what it's length is
          byte[] targetName = readSecurityBufferTarget(msg, 12);
  
          // now we convert it to a string
          int flags = msgFlags == null ? extractFlagsFromType2Message(msg)
                  : msgFlags;
          if (ByteUtilities.isFlagSet(flags, FLAG_NEGOTIATE_UNICODE)) {
              return new String(targetName, "UTF-16LE");
          }
          
          return new String(targetName, "ASCII");
      }
docs: Extracts the target name from the type 2 message.
  
  @param msg the type 2 message byte array
  @param msgFlags the flags if null then flags are extracted from the
  type 2 message
  @return the target name
  @throws UnsupportedEncodingException if unable to use the
  needed UTF-16LE or ASCII charsets