useAndWipe
Executes a block with a byte array and automatically wipes it afterward.
Use case: Ensures memory is wiped even if exceptions occur:
val keys = MemoryUtils.useAndWipe(seed) { seedBytes ->
deriveKeys(seedBytes)
}
// seed is wiped here, even if deriveKeys() throwsContent copied to clipboard
Guarantee:
The data is ALWAYS wiped after use, even on exceptions
Exceptions are re-thrown after wiping
Return
Result of the block
Parameters
data
Byte array to use and wipe
block
Lambda that uses the byte array
Throws
exception thrown by the block (after wiping data)