I've read that for passwords, it's more ideal to use char[] since Strings are immutable.
Problem is, I need to pass a password argument to a third party dependency that invokes an http call. It only accepts strings. The call involves sending in a password in the message, so I use the method:
new Request.Builder()
.url("notmyapi.com/login")
.method("POST", new FormBody.Builder()
.add("name", username)
.add("password", password)
.build())
.build()
I know it's probably bad that the web api is just accepting a password as it is instead of accepting a base64 version or whatever, but it's not mine, and I just simply have to do my job.
Question:
Since I'm now passing around the password as char[], but the .add(key, value) method above accepts only a string, is it safe to do .add("password", new String(password)) ? Will this not create a new String instance in the memory which I'm supposedly trying to avoid for security concerns?