コード例 #1
0
  private byte[] createRFC2617RequestDigest(
      final byte[] ha1, final byte[] ha2, final DigestContext context) {
    final MessageDigest digest = context.getDigest();
    final Map<DigestAuthorizationToken, String> parsedHeader = context.getParsedHeader();

    byte[] nonce =
        parsedHeader.get(DigestAuthorizationToken.NONCE).getBytes(StandardCharsets.UTF_8);
    byte[] nonceCount =
        parsedHeader.get(DigestAuthorizationToken.NONCE_COUNT).getBytes(StandardCharsets.UTF_8);
    byte[] cnonce =
        parsedHeader.get(DigestAuthorizationToken.CNONCE).getBytes(StandardCharsets.UTF_8);
    byte[] qop =
        parsedHeader.get(DigestAuthorizationToken.MESSAGE_QOP).getBytes(StandardCharsets.UTF_8);

    try {
      digest.update(ha1);
      digest.update(COLON);
      digest.update(nonce);
      digest.update(COLON);
      digest.update(nonceCount);
      digest.update(COLON);
      digest.update(cnonce);
      digest.update(COLON);
      digest.update(qop);
      digest.update(COLON);
      digest.update(ha2);

      return HexConverter.convertToHexBytes(digest.digest());
    } finally {
      digest.reset();
    }
  }
コード例 #2
0
  private byte[] createHA2Auth(final DigestContext context) {
    byte[] digestUri =
        context
            .getParsedHeader()
            .get(DigestAuthorizationToken.DIGEST_URI)
            .getBytes(StandardCharsets.UTF_8);

    MessageDigest digest = context.getDigest();
    try {
      digest.update(COLON);
      digest.update(digestUri);

      return HexConverter.convertToHexBytes(digest.digest());
    } finally {
      digest.reset();
    }
  }