example:
https://github.com/andy-goryachev/PasswordSafe/blob/master/s...
byte[] key = generateKey(); try { // sensitive operation } finally { Crypto.zero(key); }
once the operation finishes, the memory is cleared (and possibly subject to gc)
the problem is that some java classes, for instance BigInteger, are not designed for cryptographic operations - it's underlying arrays are not easily accessible (save for reflection).
A very good point, thank you.
What could be done to mitigate this? Direct ByteBuffer per
https://stackoverflow.com/questions/5670862/bytebuffer-alloc...
?
Assuming you mean oracles implementation, it's likely that it is.
https://www.sjoerdlangkemper.nl/2016/05/22/should-passwords-... http://www.daemonology.net/blog/2014-09-04-how-to-zero-a-buf... https://man.openbsd.org/explicit_bzero.3
https://github.com/andy-goryachev/PasswordSafe/blob/master/s...
Curiously, RAM encryption, and its relative - clearing secrets from memory when not in use - cannot be added to the Bouncycastle library because they use java BigInteger (unless reflection is used of course).