How can I ensure that a Java object (containing cryptographic material) is zeroized?

Posted by Jeremy Powell on Stack Overflow See other posts from Stack Overflow or by Jeremy Powell
Published on 2010-03-23T19:23:16Z Indexed on 2010/03/23 19:33 UTC
Read the original article Hit count: 261

Filed under:
|
|
|

My concern is that cryptographic keys and secrets that are managed by the garbage collector may be copied and moved around in memory without zeroization.

As a possible solution, is it enough to:

public class Key {
  private char[] key;
  // ...
  protected void finalize() throws Throwable { 
    try {
      for(int k = 0; k < key.length; k++) {
        key[k] = '\0';
      }
    } catch (Exception e) {
      //...
    } finally {
      super.finalize();
    }
  }
  // ...
}

© Stack Overflow or respective owner

Related posts about java

Related posts about security