com.darwinsys.security.BasicAuth Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of darwinsys-api Show documentation
Show all versions of darwinsys-api Show documentation
Ian Darwin's assorted Java stuff,
assembled as an API.
package com.darwinsys.security;
import java.util.Base64;
public class BasicAuth {
final static Base64.Encoder encoder = Base64.getEncoder();
/**
* Given a username and password, returns the complete value part
* of the basic-auth header, "Basic" + " " + base64(username+":"+passwd)
* @param username The username
* @param password The password
* @return The finished header.
*/
public static String makeHeader(String username, String password) {
return String.format("Basic %s",
encoder.encodeToString((username + ":" + password).getBytes()));
}
}