3

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.

1
  • 2
    What makes you think it is wrong? I can reproduce your "wrong" example both in code and on www.base64encode.org - my guess is that your "right output" is wrong. Commented Nov 9, 2015 at 8:34

1 Answer 1

3

The problem is not in the Base64-encoding but in constructing your string. Basic-Authentication requires username:password but your are missing the :.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.