| 51 | } |
| 52 | |
| 53 | private static String buildHeader(String username, String realm, String nonce, String uri, String nc, String cnonce, String qop, String response, String opaque) { |
| 54 | List<String> fields = new ArrayList<>(); |
| 55 | fields.add("username=\"" + username + "\""); |
| 56 | fields.add("realm=\"" + realm + "\""); |
| 57 | fields.add("nonce=\"" + nonce + "\""); |
| 58 | fields.add("uri=\"" + uri + "\""); |
| 59 | boolean hasQop = !qop.isEmpty(); |
| 60 | if (hasQop) fields.add("cnonce=\"" + cnonce + "\""); |
| 61 | if (hasQop) fields.add("nc=" + nc); |
| 62 | if (hasQop) fields.add("qop=" + qop); |
| 63 | fields.add("response=\"" + response + "\""); |
| 64 | if (opaque != null) fields.add("opaque=\"" + opaque + "\""); |
| 65 | return "Digest " + String.join(", ", fields); |
| 66 | } |
| 67 | |
| 68 | private static String newCnonce() { |
| 69 | return UUID.randomUUID().toString().replace("-", ""); |