diff a/src/java.base/share/classes/sun/security/x509/X509CertImpl.java b/src/java.base/share/classes/sun/security/x509/X509CertImpl.java --- a/src/java.base/share/classes/sun/security/x509/X509CertImpl.java +++ b/src/java.base/share/classes/sun/security/x509/X509CertImpl.java @@ -1974,28 +1974,12 @@ X509Certificate cert) { try { byte[] encCertInfo = cert.getEncoded(); MessageDigest md = MessageDigest.getInstance(algorithm); byte[] digest = md.digest(encCertInfo); - StringBuilder sb = new StringBuilder(digest.length * 2); - for (int i = 0; i < digest.length; i++) { - byte2hex(digest[i], sb); - } - return sb.toString(); + return Hex.encoder().encode(digest); } catch (NoSuchAlgorithmException | CertificateEncodingException e) { // ignored } return ""; } - - /** - * Converts a byte to hex digit and writes to the supplied builder - */ - private static void byte2hex(byte b, StringBuilder buf) { - char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', - '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - int high = ((b & 0xf0) >> 4); - int low = (b & 0x0f); - buf.append(hexChars[high]) - .append(hexChars[low]); - } }