content: package com.r00t.util;
  
  import com.r00t.config.AppConfig;
  import nc.bs.framework.server.token.MD5Util;
  
  import java.security.MessageDigest;
  
  public class TokenGenerator {
      private TokenGenerator() {}
      
      public static String generateToken(String userCode) {
          return generateToken(userCode, AppConfig.TOKEN_SEED);
      }
      
      public static String generateToken(String userCode, String tokenSeed) {
          byte[] md5 = calculateMD5(tokenSeed.getBytes(), userCode.getBytes());
          return MD5Util.byteToHexString(md5);
      }
      
      public static String generateDefaultToken(String userCode) {
          return generateToken(userCode, AppConfig.DEFAULT_TOKEN_SEED);
      }
      
      private static byte[] calculateMD5(byte[] key, byte[] tokens) {
          try {
              MessageDigest md = MessageDigest.getInstance("SHA-1");
              md.update(tokens);
              md.update(key);
              return md.digest();
          } catch (Exception e) {
              throw new RuntimeException("Token generation failed");
          }
      }
  }
  
  