Java Code Examples for io.undertow.util.HexConverter#convertToHexString()

The following examples show how to use io.undertow.util.HexConverter#convertToHexString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DigestAuthTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a response value from the supplied parameters.
 *
 * @return The generated Hex encoded MD5 digest based response.
 */
private String createResponse(final String userName, final String realm, final String password, final String method,
        final String uri, final String nonce) throws Exception {
    MessageDigest digest = MessageDigest.getInstance("MD5");
    digest.update(userName.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(realm.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(password.getBytes(UTF_8));

    byte[] ha1 = HexConverter.convertToHexBytes(digest.digest());

    digest.update(method.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(uri.getBytes(UTF_8));

    byte[] ha2 = HexConverter.convertToHexBytes(digest.digest());

    digest.update(ha1);
    digest.update((byte) ':');
    digest.update(nonce.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(ha2);

    return HexConverter.convertToHexString(digest.digest());
}
 
Example 2
Source File: DigestAuthentication2069TestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a response value from the supplied parameters.
 *
 * @return The generated Hex encoded MD5 digest based response.
 */
private String createResponse(final String userName, final String realm, final String password, final String method,
        final String uri, final String nonce) throws Exception {
    MessageDigest digest = MessageDigest.getInstance("MD5");
    digest.update(userName.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(realm.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(password.getBytes(UTF_8));

    byte[] ha1 = HexConverter.convertToHexBytes(digest.digest());

    digest.update(method.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(uri.getBytes(UTF_8));

    byte[] ha2 = HexConverter.convertToHexBytes(digest.digest());

    digest.update(ha1);
    digest.update((byte) ':');
    digest.update(nonce.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(ha2);

    return HexConverter.convertToHexString(digest.digest());
}
 
Example 3
Source File: DigestAuthenticationAuthTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private static String createNonce() {
    // This if just for testing so we are not concerned with how securely the client side nonce is.
    Random rand = new Random();
    byte[] nonceBytes = new byte[32];
    rand.nextBytes(nonceBytes);

    return HexConverter.convertToHexString(nonceBytes);
}
 
Example 4
Source File: DigestAuthenticationAuthTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a response value from the supplied parameters.
 *
 * @return The generated Hex encoded MD5 digest based response.
 */
private static String createResponse(final String userName, final String realm, final String password, final String method,
        final String uri, final String nonce, final String nonceCount, final String cnonce) throws Exception {
    MessageDigest digest = MessageDigest.getInstance("MD5");
    digest.update(userName.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(realm.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(password.getBytes(UTF_8));

    byte[] ha1 = HexConverter.convertToHexBytes(digest.digest());

    digest.update(method.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(uri.getBytes(UTF_8));

    byte[] ha2 = HexConverter.convertToHexBytes(digest.digest());

    digest.update(ha1);
    digest.update((byte) ':');
    digest.update(nonce.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(nonceCount.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(cnonce.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(DigestQop.AUTH.getToken().getBytes(UTF_8));
    digest.update((byte) ':');

    digest.update(ha2);

    return HexConverter.convertToHexString(digest.digest());
}
 
Example 5
Source File: DigestAuthenticationAuthTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private static String createRspAuth(final String userName, final String realm, final String password, final String uri,
        final String nonce, final String nonceCount, final String cnonce) throws Exception {
    MessageDigest digest = MessageDigest.getInstance("MD5");
    digest.update(userName.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(realm.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(password.getBytes(UTF_8));

    byte[] ha1 = HexConverter.convertToHexBytes(digest.digest());

    digest.update((byte) ':');
    digest.update(uri.getBytes(UTF_8));

    byte[] ha2 = HexConverter.convertToHexBytes(digest.digest());

    digest.update(ha1);
    digest.update((byte) ':');
    digest.update(nonce.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(nonceCount.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(cnonce.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(DigestQop.AUTH.getToken().getBytes(UTF_8));
    digest.update((byte) ':');

    digest.update(ha2);

    return HexConverter.convertToHexString(digest.digest());
}