Class Zeroization
All buffers passed in are overwritten in place using Arrays.fill(byte[], byte) and
Arrays.fill(char[], char), which is the only portable mechanism available on the JVM.
JIT register spills, JVM string interning, and Bouncy Castle internal pools are NOT addressed
by these methods (see SECURE_MEMORY.md for the complete capability matrix).
-
Method Summary
Modifier and TypeMethodDescriptionstatic voiddestroyIfPossible(Object obj) CallsDestroyable.destroy()if the supplied object implementsDestroyableand is not yet destroyed.static voidzeroize(byte[] buf) Overwrites every element with0x00.static voidzeroize(char[] buf) Overwrites every element with the space character' '.
-
Method Details
-
zeroize
public static void zeroize(byte[] buf) Overwrites every element with0x00. Null-safe (no-op onnull). -
zeroize
public static void zeroize(char[] buf) Overwrites every element with the space character' '. Null-safe (no-op onnull).Space-fill (rather than
' ') is a deliberate choice: spaces are visible in heap dumps as printable text, making accidental retention easier to spot during forensic analysis. The security guarantee is identical — the original sensitive content is replaced. -
destroyIfPossible
CallsDestroyable.destroy()if the supplied object implementsDestroyableand is not yet destroyed. SwallowsDestroyFailedException, which the JDK throws by default forSecretKeySpecand several Bouncy Castle types.When this exception is swallowed, zeroization of the wrapping
byte[]remains the caller's responsibility.SecretBufferprovides the standard pattern.Null-safe: passing
nullis a no-op.
-