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.
The problem is not in the Base64-encoding but in constructing your string. Basic-Authentication requires username:password but your are missing the :.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With