6383195: javax.crypto.spec.PBEKeySpec is not thread safe

Reviewed-by: weijun
This commit is contained in:
Bradford Wetmore 2022-07-28 22:04:44 +00:00
parent e052d7f4bc
commit 791fc5791a
2 changed files with 98 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -173,7 +173,7 @@ public class PBEKeySpec implements KeySpec {
* Clears the internal copy of the password.
*
*/
public final void clearPassword() {
public final synchronized void clearPassword() {
if (password != null) {
Arrays.fill(password, ' ');
password = null;
@ -191,7 +191,7 @@ public class PBEKeySpec implements KeySpec {
* calling <code>clearPassword</code> method.
* @return the password.
*/
public final char[] getPassword() {
public final synchronized char[] getPassword() {
if (password == null) {
throw new IllegalStateException("password has been cleared");
}