All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.darwinsys.security.BasicAuth Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
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()));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy