예제 #1
0
 private static String toHexString(byte[] data) {
   StringBuilder buffer = StringUtils.stringBuilder();
   for (int i = 0; i < data.length; i++) {
     buffer.append(Integer.toHexString((data[i] & 0xf0) >>> 4));
     buffer.append(Integer.toHexString(data[i] & 0x0f));
   }
   return buffer.toString();
 }
예제 #2
0
 private static void appendBase16(StringBuilder buf, byte[] bytes) {
   int base = 16;
   for (byte b : bytes) {
     int bi = 0xff & b;
     int c = '0' + (bi / base) % base;
     if (c > '9') c = 'a' + (c - '0' - 10);
     buf.append((char) c);
     c = '0' + bi % base;
     if (c > '9') c = 'a' + (c - '0' - 10);
     buf.append((char) c);
   }
 }
예제 #3
0
    private byte[] dataDigest(StringBuilder sb, String digestUri, MessageDigest md) {

      sb.append(methodName).append(':').append(digestUri);
      if ("auth-int".equals(qop)) {
        sb.append(':').append(EMPTY_ENTITY_MD5);

      } else if (qop != null && !qop.equals("auth")) {
        throw new UnsupportedOperationException("Digest qop not supported: " + qop);
      }

      return md5FromRecycledStringBuilder(sb, md);
    }
예제 #4
0
    private byte[] secretDigest(StringBuilder sb, MessageDigest md) {

      sb.append(principal).append(':').append(realmName).append(':').append(password);
      byte[] ha1 = md5FromRecycledStringBuilder(sb, md);

      if (algorithm == null || algorithm.equals("MD5")) {
        return ha1;
      } else if ("MD5-sess".equals(algorithm)) {
        appendBase16(sb, ha1);
        sb.append(':').append(nonce).append(':').append(cnonce);
        return md5FromRecycledStringBuilder(sb, md);
      }

      throw new UnsupportedOperationException("Digest algorithm not supported: " + algorithm);
    }
예제 #5
0
 private void appendDataBase(StringBuilder sb) {
   sb.append(':').append(nonce).append(':');
   if ("auth".equals(qop) || "auth-int".equals(qop)) {
     sb.append(nc).append(':').append(cnonce).append(':').append(qop).append(':');
   }
 }