src/java.base/share/classes/com/sun/crypto/provider/PBEKey.java
changeset 48560 46e99460e8c9
parent 47216 71c04702a3d5
child 51293 53c3b460503c
equal deleted inserted replaced
48559:607d78d0e6f7 48560:46e99460e8c9
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package com.sun.crypto.provider;
    26 package com.sun.crypto.provider;
    27 
    27 
       
    28 import java.lang.ref.Reference;
    28 import java.security.MessageDigest;
    29 import java.security.MessageDigest;
    29 import java.security.KeyRep;
    30 import java.security.KeyRep;
    30 import java.security.spec.InvalidKeySpecException;
    31 import java.security.spec.InvalidKeySpecException;
    31 import java.util.Locale;
    32 import java.util.Locale;
    32 import javax.crypto.SecretKey;
    33 import javax.crypto.SecretKey;
    78         CleanerFactory.cleaner().register(this,
    79         CleanerFactory.cleaner().register(this,
    79                 () -> java.util.Arrays.fill(k, (byte)0x00));
    80                 () -> java.util.Arrays.fill(k, (byte)0x00));
    80     }
    81     }
    81 
    82 
    82     public byte[] getEncoded() {
    83     public byte[] getEncoded() {
    83         return this.key.clone();
    84         // The key is zeroized by finalize()
       
    85         // The reachability fence ensures finalize() isn't called early
       
    86         byte[] result = key.clone();
       
    87         Reference.reachabilityFence(this);
       
    88         return result;
    84     }
    89     }
    85 
    90 
    86     public String getAlgorithm() {
    91     public String getAlgorithm() {
    87         return type;
    92         return type;
    88     }
    93     }