I talkam talking about athe Java implementation. Is it more secure to use reflection in order to access to the internal Field value of type char[]char[]
inside a java.lang.String Instanceinstance and overwrite the containing values like the following example?
As a Examplean example why someone could use it: Someone enterenters a Password and after the Password is used (maybe Authorization)this this exact String will be of no use after that, except to read out of the Memory, he could overwrite it and the Password as clear readable String will be out of the memory.
Example Implementation:
SecureRandom random = SecureRandom.getInstanceStrong();
String source = "1234SecureThingy"
Field charField = String.class.getDeclaredField("value");
charField.setAccessible(true);
char[] noise = new char[source.length()];
for (int i = 0; i < source.length(); i++) {
noise[i] = (char) random.nextInt(Character.MAX_VALUE + 1);
}
charField.set(source, noise);
TL;DR: Is it more secure to Remove the value of a String with Reflection?