ThumbprintTrustManager implements X509TrustManager { public static String toHex(byte[] bytes, String separator) { StringBuffer result = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { int unsignedByte = bytes[i] & 0xff; if (unsignedByte < 16) { result.append("0"); } result.append(Integer.toHexString(unsignedByte)); if (separator != null && i + 1 < bytes.length) { result.append(separator); } } return result.toString(); } ThumbprintTrustManager(); synchronized void add(String thumbprint, Object owner); void add(String thumbprint); synchronized void remove(String thumbprint, Object owner); void remove(String thumbprint); synchronized boolean hasThumbprint(String thumbprint); @Override void checkClientTrusted(X509Certificate[] chain, String authType); static String toHex(byte[] bytes, String separator); static String toHex(byte[] bytes); String certificateToThumbprint(Certificate cert); @Override void checkServerTrusted(X509Certificate[] chain, String authType); @Override X509Certificate[] getAcceptedIssuers();  }
@Test(groups = { "TestThumbprintTrustManager" }) public void testToHex() { byte[] bytes = thumbprint.getBytes(); StringBuffer numbers = new StringBuffer(); for (byte b : bytes) { int num = b & 0xff; numbers.append(Integer.toHexString(num)); } assertEquals(ThumbprintTrustManager.toHex(bytes), numbers.toString()); }