Пример #1
0
  /**
   * @ibm-not-published
   * @deprecated
   */
  public static String encrypt(String pwd, String ctx) {
    if (pwd == null) {
      return null;
    }
    int offset;
    if (StringUtil.isNotEmpty(ctx)) {
      int acc = Math.abs((int) (ctx.hashCode() % ENCRYPTION.length));
      offset = Math.min(ENCRYPTION.length, acc);
    } else {
      offset = Math.min(ENCRYPTION.length, (int) (Math.random() * ENCRYPTION.length));
    }

    FastStringBuffer b = new FastStringBuffer();
    b.append('[');
    // Write the offset/count
    encryptChar(b, 0, (char) offset);
    encryptChar(b, offset++, (char) (pwd.length()));
    for (int i = 0; i < Math.max(MINPWDLENGTH, pwd.length()); i++) {
      char c;
      if (i < pwd.length()) {
        c = pwd.charAt(i);
      } else {
        if (StringUtil.isNotEmpty(ctx)) {
          int pwdlen = pwd.length();
          c = ctx.charAt((i - pwdlen) % ctx.length());
        } else {
          c = (char) (Math.random() * 64 + 32);
        }
      }
      encryptChar(b, offset++, c);
    }
    b.append(']');
    return b.toString();
  }