Irretrievably destroying data in Java

后端 未结 10 1423
时光说笑
时光说笑 2020-12-10 04:26

Is there anyway in Java to delete data (e.g., a variable value, object) and be sure it can\'t be recovered from memory? Does assigning null to a variable in Jav

10条回答
  •  感情败类
    2020-12-10 05:00

    Primitive data (byte, char, int, double) and arrays of them (byte[], ...) are erasable by writing new random content into them.

    Object data have to be sanitized by overwriting their primitive properties; setting a variable to null just makes the object available for GC, but not immediately dead. A dump of VM will contain them for anyone to see.

    Immutable data such as String cannot be overwritten in any way. Any modification just makes a copy. You shall avoid keeping sensitive data in such objects.

    P.S. If we talk about passwords, it's better to use crypto-strong hash functions (MD5, SHA1, ...), and never ever work with passwords in clear text.

提交回复
热议问题