package com.afrozaar.wordpress.wpapi.v2.util;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

import java.util.Base64;

public class AuthUtil {

    public static HttpHeaders createHeaders(String username, String password) {
        HttpHeaders httpHeaders = new HttpHeaders();
        final byte[] encodedAuth = Base64.getEncoder().encode((username + ":" + password).getBytes());
        //byte[] encodedAuth = Base64.encode((username + ":" + password).getBytes(Charset.forName("US-ASCII")));
        final String authHeader = "Basic " + new String(encodedAuth);
        httpHeaders.set("Authorization", authHeader);
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);

        return httpHeaders;
    }

    public static HttpEntity<String> basicAuth(String username, String password) {
        return new HttpEntity<>(createHeaders(username, password));
    }
}

@@ -375,96 +375,308 @@
 nal 
-byte%5B%5D encodedAuth = Base64.getEncoder().encode((username + %22:%22 + password).getBytes());
+Two%3CString, String%3E authHeader = authTuple(username, password);%0A        httpHeaders.set(authHeader.k, authHeader.v);%0A        httpHeaders.setContentType(MediaType.APPLICATION_JSON);%0A%0A        return httpHeaders;%0A    %7D%0A%0A    public static Two%3CString, String%3E authTuple(String username, String password) %7B
 %0A   
@@ -684,10 +684,14 @@
     
-//
+final 
 byte
@@ -714,16 +714,29 @@
  Base64.
+getEncoder().
 encode((
@@ -775,254 +775,86 @@
 tes(
-Charset.forName(%22US-ASCII%22)));%0A        final String authHeader = %22Basic %22 + new String(encodedAuth);%0A        httpHeaders.set(%22Authorization%22, authHeader);%0A        httpHeaders.setContentType(MediaType.APPLICATION_JSON);%0A%0A        return httpHeaders
+));%0A        return Two.of(%22Authorization%22, %22Basic %22 + new String(encodedAuth))
 ;%0A  

Clean up AuthUtil.