I am building a web using Spring. I want to encode string to send as a Basic Authentication.
Here is the code,
private String authUsername = "admin";
private String authPassword = "admin";
private String unEncode = authUsername+authPassword;
private byte[] encodedBytes = Base64.encodeBase64(unEncode.getBytes());
private String encode = new String(encodedBytes);
private String authenCode = "Basic "+encode;
The result is "Basic YWRtaW5hZG1pbg==" And it is wrong.
The right output should be "Basic YWRtaW46YWRtaW4="
What I did wrong or What I missed ?
Thanks.