提交 3cad1e6f 编写于 作者: I igerasim

8172525: Improve key keying case

Reviewed-by: mullan
上级 41156ddc
...@@ -76,7 +76,7 @@ final class DESKey implements SecretKey { ...@@ -76,7 +76,7 @@ final class DESKey implements SecretKey {
DESKeyGenerator.setParityBit(this.key, 0); DESKeyGenerator.setParityBit(this.key, 0);
} }
public byte[] getEncoded() { public synchronized byte[] getEncoded() {
// Return a copy of the key, rather than a reference, // Return a copy of the key, rather than a reference,
// so that the key data cannot be modified from outside // so that the key data cannot be modified from outside
return this.key.clone(); return this.key.clone();
...@@ -151,10 +151,12 @@ final class DESKey implements SecretKey { ...@@ -151,10 +151,12 @@ final class DESKey implements SecretKey {
*/ */
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
synchronized (this) {
if (this.key != null) { if (this.key != null) {
java.util.Arrays.fill(this.key, (byte)0x00); java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null; this.key = null;
} }
}
} finally { } finally {
super.finalize(); super.finalize();
} }
......
...@@ -78,7 +78,7 @@ final class DESedeKey implements SecretKey { ...@@ -78,7 +78,7 @@ final class DESedeKey implements SecretKey {
DESKeyGenerator.setParityBit(this.key, 16); DESKeyGenerator.setParityBit(this.key, 16);
} }
public byte[] getEncoded() { public synchronized byte[] getEncoded() {
return this.key.clone(); return this.key.clone();
} }
...@@ -152,10 +152,12 @@ final class DESedeKey implements SecretKey { ...@@ -152,10 +152,12 @@ final class DESedeKey implements SecretKey {
*/ */
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
synchronized (this) {
if (this.key != null) { if (this.key != null) {
java.util.Arrays.fill(this.key, (byte)0x00); java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null; this.key = null;
} }
}
} finally { } finally {
super.finalize(); super.finalize();
} }
......
...@@ -72,7 +72,7 @@ final class PBEKey implements SecretKey { ...@@ -72,7 +72,7 @@ final class PBEKey implements SecretKey {
type = keytype; type = keytype;
} }
public byte[] getEncoded() { public synchronized byte[] getEncoded() {
return this.key.clone(); return this.key.clone();
} }
...@@ -147,10 +147,12 @@ final class PBEKey implements SecretKey { ...@@ -147,10 +147,12 @@ final class PBEKey implements SecretKey {
*/ */
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
synchronized (this) {
if (this.key != null) { if (this.key != null) {
java.util.Arrays.fill(this.key, (byte)0x00); java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null; this.key = null;
} }
}
} finally { } finally {
super.finalize(); super.finalize();
} }
......
...@@ -190,7 +190,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey { ...@@ -190,7 +190,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
return key; return key;
} }
public byte[] getEncoded() { public synchronized byte[] getEncoded() {
return key.clone(); return key.clone();
} }
...@@ -202,7 +202,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey { ...@@ -202,7 +202,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
return iterCount; return iterCount;
} }
public char[] getPassword() { public synchronized char[] getPassword() {
return passwd.clone(); return passwd.clone();
} }
...@@ -264,6 +264,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey { ...@@ -264,6 +264,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
*/ */
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
synchronized (this) {
if (this.passwd != null) { if (this.passwd != null) {
java.util.Arrays.fill(this.passwd, '0'); java.util.Arrays.fill(this.passwd, '0');
this.passwd = null; this.passwd = null;
...@@ -272,6 +273,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey { ...@@ -272,6 +273,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
java.util.Arrays.fill(this.key, (byte)0x00); java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null; this.key = null;
} }
}
} finally { } finally {
super.finalize(); super.finalize();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册