4949import java .security .spec .RSAPublicKeySpec ;
5050import java .util .ArrayList ;
5151import java .util .Arrays ;
52+ import java .util .HexFormat ;
5253import java .util .List ;
5354import java .util .logging .Logger ;
5455import java .util .stream .Collectors ;
55- import org .apache .commons .codec .binary .Hex ;
5656import org .apache .commons .io .FileUtils ;
5757import org .bouncycastle .asn1 .pkcs .PrivateKeyInfo ;
5858import org .bouncycastle .asn1 .x509 .SubjectPublicKeyInfo ;
@@ -84,6 +84,7 @@ public final class PEMEncodable {
8484 @ NonNull
8585 private final Object object ;
8686
87+ private static final HexFormat HEX_FORMAT = HexFormat .ofDelimiter (":" );
8788 private static final Provider BOUNCY_CASTLE_PROVIDER ;
8889
8990 static {
@@ -476,7 +477,7 @@ public String getPrivateKeyFingerprint() {
476477 if (key == null ) {
477478 return null ;
478479 }
479- return hexEncode (getKeyDigestSHA1 (key ));
480+ return HEX_FORMAT . formatHex (getKeyDigestSHA1 (key ));
480481 }
481482
482483 /**
@@ -492,7 +493,7 @@ public String getPublicKeyFingerprint() {
492493 if (key == null ) {
493494 return null ;
494495 }
495- return hexEncode (getKeyDigestMD5 (key ));
496+ return HEX_FORMAT . formatHex (getKeyDigestMD5 (key ));
496497 }
497498
498499 /**
@@ -543,24 +544,5 @@ public static byte[] getKeyDigest(@NonNull Key k, @NonNull String algorithm) thr
543544 return md .digest ();
544545 }
545546
546- /**
547- * Encode {@link byte[]} in hex formated string "ab:cd:ef:...:12"
548- *
549- * @param data to be encoded
550- * @return hex formated string "ab:cd:ef:...:12"
551- */
552- @ NonNull
553- private static String hexEncode (@ NonNull byte [] data ) {
554- char [] hex = Hex .encodeHex (data );
555- StringBuilder buf = new StringBuilder (hex .length + Math .max (0 , hex .length / 2 - 1 ));
556- for (int i = 0 ; i < hex .length ; i += 2 ) {
557- if (i > 0 ) {
558- buf .append (':' );
559- }
560- buf .append (hex , i , 2 );
561- }
562- return buf .toString ();
563- }
564-
565547 private static final Logger LOGGER = Logger .getLogger (PEMEncodable .class .getName ());
566548}
0 commit comments