I'm trying to preserve the password
as char[]
but in the second step, I'm converting it to a String again. Is there a way to to this in a better way?
char[] password = {'g', 'r', 'e'};
String toEncode = username + new String(password);
byte[] encoding = Base64.encodeBase64(toEncode.getBytes(Charset.forName(StandardCharsets.UTF_8.name())));
One option would be:
char[] toEncode = username.toCharArray() + password;
byte[] encoding = Base64.encodeBase64(new String(toEncode).getBytes(Charset.forName(StandardCharsets.UTF_8.name())));
What I'm asking is is there a better way to achieve it without using new String()