Context
I recently had a cryptography lecture and we discussed about persistence of critical elements in memory. Typically, C/C++ library Libsodium suggests to clear any buffer that contained sensitive information, such as a secret (ref). I know that GuardedString
is backed by an array of bytes and the docs recommends to call the method dispose
once the stored secret is no longer used, that fills the array of bytes using Arrays.fill
.
Question
Does the JVM guarantee that the values of the byte array are gone when overwritten or may the original values remain in memory under certain conditions ? For example, unused/unreferenced String
s are conserved in the Java String Pool until a garbage collection is triggered. Are there similar caching or mechanisms for other types such as the byte array that can compromise the secret that should be disposed from the GuardedString
? Any reference in the specs of the JVM ?
Many thanks !