code: public static String toHexString(byte[] data, boolean upper)
      {
          if (data == null)
          {
              return null;
          }
  
          char[] table = (upper ? UPPER_HEX_CHARS : LOWER_HEX_CHARS);
          char[] chars = new char[data.length * 2];
  
          for (int i = 0; i < data.length; ++i)
          {
              chars[i * 2    ] = table[ (data[i] & 0xF0) >> 4 ];
              chars[i * 2 + 1] = table[ (data[i] & 0x0F)      ];
          }
  
          return new String(chars);
      }
docs: Convert a byte array to a hex string.
  
  @param data
  An input byte array.
  
  @param upper
  {@code true} to generate a upper-case hex string.
  {@code false} to generate a lower-case hex string.
  
  @return
  A hex string. if {@code data} is {@code null},
  {@code null} is returned.