RPC-GWT序列化/ java.util.Date编码 [英] RPC-GWT Serialization/java.util.Date Encoding

查看:198
本文介绍了RPC-GWT序列化/ java.util.Date编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个序列化GWT请求的脚本,并且编码日期值的问题符合RPC-GWT标准。通过HTTP日志,我注意到日期值被转换为7个字符的字符串,但是我无法识别这些模式使用的算法。

I'm creating a script that serializes GWT requests and I have a problem encoding date values to comply with RPC-GWT standard. Going through the HTTP logs I noticed that date values are converted to some strings of 7 characters but I can't recognize the algorithm used by those patterns.

有谁知道哪个算法用于加密这些日期值?

Does anyone know which algorithm is used to encrypt those date values?

推荐答案

这些日期值被序列化为长度值=>毫秒从历元(1月1日1970),然后以包装形式作为base64序列化以变得更短的字符串。这里看看:

Those date values are serialized as long values => milliseconds since epoch (January 1 1970) and then serialized in a packed form as base64 to become shorter strings. Here have a look:

/**
   * Parse a string containing a base-64 encoded version of a long value.
   *
   * Keep this synchronized with the version in Base64Utils.
   */
  static long longFromBase64(String value) {
    int pos = 0;
    long longVal = base64Value(value.charAt(pos++));
    int len = value.length();
    while (pos < len) {
      longVal <<= 6;
      longVal |= base64Value(value.charAt(pos++));
    }
    return longVal;
  }
  /**
   * Return an optionally single-quoted string containing a base-64 encoded
   * version of the given long value.
   *
   * Keep this synchronized with the version in Base64Utils.
   */
  static String longToBase64(long value) {
    // Convert to ints early to avoid need for long ops
    int low = (int) (value & 0xffffffff);
    int high = (int) (value >> 32);
    StringBuilder sb = new StringBuilder();
    boolean haveNonZero = base64Append(sb, (high >> 28) & 0xf, false);
    haveNonZero = base64Append(sb, (high >> 22) & 0x3f, haveNonZero);
    haveNonZero = base64Append(sb, (high >> 16) & 0x3f, haveNonZero);
    haveNonZero = base64Append(sb, (high >> 10) & 0x3f, haveNonZero);
    haveNonZero = base64Append(sb, (high >> 4) & 0x3f, haveNonZero);
    int v = ((high & 0xf) << 2) | ((low >> 30) & 0x3);
    haveNonZero = base64Append(sb, v, haveNonZero);
    haveNonZero = base64Append(sb, (low >> 24) & 0x3f, haveNonZero);
    haveNonZero = base64Append(sb, (low >> 18) & 0x3f, haveNonZero);
    haveNonZero = base64Append(sb, (low >> 12) & 0x3f, haveNonZero);
    base64Append(sb, (low >> 6) & 0x3f, haveNonZero);
    base64Append(sb, low & 0x3f, true);
    return sb.toString();
  }
  private static boolean base64Append(StringBuilder sb, int digit, boolean haveNonZero) {
    if (digit > 0) {
      haveNonZero = true;
    }
    if (haveNonZero) {
      int c;
      if (digit < 26) {
        c = 'A' + digit;
      } else if (digit < 52) {
        c = 'a' + digit - 26;
      } else if (digit < 62) {
        c = '0' + digit - 52;
      } else if (digit == 62) {
        c = '$';
      } else {
        c = '_';
      }
      sb.append((char) c);
    }
    return haveNonZero;
  }
  // Assume digit is one of [A-Za-z0-9$_]
  private static int base64Value(char digit) {
    if (digit >= 'A' && digit <= 'Z') {
      return digit - 'A';
    }
    // No need to check digit <= 'z'
    if (digit >= 'a') {
      return digit - 'a' + 26;
    }
    if (digit >= '0' && digit <= '9') {
      return digit - '0' + 52;
    }
    if (digit == '$') {
      return 62;
    }
    // digit == '_'
    return 63;

 }

我在PHP中以 Colin Alworth

这篇关于RPC-GWT序列化/ java.util.Date编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆