diff -r f0dca628176c -r b046ba510bbc src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java --- a/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java Tue Nov 12 10:19:04 2019 +0100 +++ b/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java Tue Nov 12 01:36:17 2019 -0800 @@ -51,6 +51,8 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.util.*; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.security.AlgorithmParameters; import java.security.InvalidAlgorithmParameterException; import javax.crypto.spec.PBEParameterSpec; @@ -687,12 +689,14 @@ entry.attributes.addAll(attributes); } // set the keyId to current date - entry.keyId = ("Time " + (entry.date).getTime()).getBytes("UTF8"); + entry.keyId = ("Time " + (entry.date).getTime()).getBytes(UTF_8); // set the alias entry.alias = alias.toLowerCase(Locale.ENGLISH); // add the entry entries.put(alias.toLowerCase(Locale.ENGLISH), entry); + } catch (KeyStoreException kse) { + throw kse; } catch (Exception nsae) { throw new KeyStoreException("Key protection" + " algorithm not found: " + nsae, nsae); @@ -746,12 +750,8 @@ alias + "'"); } - try { - // set the keyId to current date - entry.keyId = ("Time " + (entry.date).getTime()).getBytes("UTF8"); - } catch (UnsupportedEncodingException ex) { - // Won't happen - } + // set the keyId to current date + entry.keyId = ("Time " + (entry.date).getTime()).getBytes(UTF_8); // set the alias entry.alias = alias.toLowerCase(Locale.ENGLISH); @@ -2499,18 +2499,18 @@ // attribute in pkcs12 with one private key entry and // associated cert-chain if (privateKeyCount == 1) { - keyId = "01".getBytes("UTF8"); + keyId = "01".getBytes(UTF_8); } else { continue; } } else { // keyId in a SecretKeyEntry is not significant - keyId = "00".getBytes("UTF8"); + keyId = "00".getBytes(UTF_8); } } entry.keyId = keyId; // restore date if it exists - String keyIdStr = new String(keyId, "UTF8"); + String keyIdStr = new String(keyId, UTF_8); Date date = null; if (keyIdStr.startsWith("Time ")) { try { @@ -2547,7 +2547,7 @@ if ((keyId == null) && (privateKeyCount == 1)) { // insert localKeyID only for EE cert or self-signed cert if (i == 0) { - keyId = "01".getBytes("UTF8"); + keyId = "01".getBytes(UTF_8); } } // Trusted certificate