MemoryUtils
Utilities for secure memory wiping of cryptographic material.
Why Memory Wiping Matters: When working with sensitive data like seeds and private keys, it's critical to minimize the time they remain in memory. JVM garbage collection is unpredictable, so we explicitly zero out byte arrays after use.
Limitations:
This is "best effort" - JVM may create copies during GC
String wiping is impossible (Strings are immutable)
For maximum security, use hardware wallets
Memory dumps can still expose keys before wiping
Best Practices:
Use ByteArray instead of String for sensitive data
Wipe ByteArray as soon as you're done with it
Use try-finally blocks to ensure wiping happens even on exceptions
Never log sensitive data
Never store seeds/keys long-term in memory
Example:
val seed = deriveSeed() // 32 bytes
try {
val keys = deriveKeys(seed)
// Use keys...
} finally {
MemoryUtils.wipe(seed) // CRITICAL: Always wipe
}