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

8172525: Improve key keying case

Reviewed-by: mullan
上级 41156ddc
......@@ -76,7 +76,7 @@ final class DESKey implements SecretKey {
DESKeyGenerator.setParityBit(this.key, 0);
}
public byte[] getEncoded() {
public synchronized 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();
......@@ -151,9 +151,11 @@ final class DESKey implements SecretKey {
*/
protected void finalize() throws Throwable {
try {
if (this.key != null) {
java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
synchronized (this) {
if (this.key != null) {
java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
}
}
} finally {
super.finalize();
......
......@@ -78,7 +78,7 @@ final class DESedeKey implements SecretKey {
DESKeyGenerator.setParityBit(this.key, 16);
}
public byte[] getEncoded() {
public synchronized byte[] getEncoded() {
return this.key.clone();
}
......@@ -152,9 +152,11 @@ final class DESedeKey implements SecretKey {
*/
protected void finalize() throws Throwable {
try {
if (this.key != null) {
java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
synchronized (this) {
if (this.key != null) {
java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
}
}
} finally {
super.finalize();
......
......@@ -72,7 +72,7 @@ final class PBEKey implements SecretKey {
type = keytype;
}
public byte[] getEncoded() {
public synchronized byte[] getEncoded() {
return this.key.clone();
}
......@@ -147,9 +147,11 @@ final class PBEKey implements SecretKey {
*/
protected void finalize() throws Throwable {
try {
if (this.key != null) {
java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
synchronized (this) {
if (this.key != null) {
java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
}
}
} finally {
super.finalize();
......
......@@ -190,7 +190,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
return key;
}
public byte[] getEncoded() {
public synchronized byte[] getEncoded() {
return key.clone();
}
......@@ -202,7 +202,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
return iterCount;
}
public char[] getPassword() {
public synchronized char[] getPassword() {
return passwd.clone();
}
......@@ -264,13 +264,15 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
*/
protected void finalize() throws Throwable {
try {
if (this.passwd != null) {
java.util.Arrays.fill(this.passwd, '0');
this.passwd = null;
}
if (this.key != null) {
java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
synchronized (this) {
if (this.passwd != null) {
java.util.Arrays.fill(this.passwd, '0');
this.passwd = null;
}
if (this.key != null) {
java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
}
}
} finally {
super.finalize();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册