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.InvalidKeyException;
@ -86,7 +87,12 @@ final class DESKey implements SecretKey {
public byte[] getEncoded() {
// Return a copy of the key, rather than a reference,
// so that the key data cannot be modified from outside
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() {