8172525: Improve key keying case

Reviewed-by: mullan, valeriep, rhalade, ahgross
This commit is contained in:
Adam Petcher 2017-04-28 10:17:46 -04:00
parent 2ad7c43b76
commit bb2e7a3311
4 changed files with 30 additions and 5 deletions

View file

@ -25,6 +25,7 @@
package com.sun.crypto.provider;
import java.lang.ref.Reference;
import java.security.MessageDigest;
import java.security.KeyRep;
import java.security.spec.InvalidKeySpecException;
@ -80,7 +81,11 @@ final class PBEKey implements SecretKey {
}
public byte[] getEncoded() {
return this.key.clone();
// The key is zeroized by finalize()
// The reachability fence ensures finalize() isn't called early
byte[] result = key.clone();
Reference.reachabilityFence(this);
return result;
}
public String getAlgorithm() {