如何使用JSSE实现SSL安全连接(11)try{ certValues.setText(getFingerprint(chain[chainIdx].getEncoded(),"MD5")+"\n"+ getFingerprint(chain[chainIdx].getEncoded(),"SHA1")); }catch(Exception fingerE) { certValues.setText("Couldn't calculate fingerprints of the certificate.\nReason: "+fingerE.getMessage()); } } } }
/** * This method calculates the fingerprint of the certificate. It takes the encoded form of * the certificate and calculates a hash value from it. * * @param certificateBytes In: The byte array of the encoded data. * @param algorithm In: The algorithm to be used for calculating the hash value. * Two are possible: MD5 and SHA1 * * @return: Returns a hex formated string of the fingerprint. */
/** * This method converts a byte array to a hex formatted string. * * @param byteData In: The data to be converted. * * @return: The formatted string. */ private String byteArrayToHex(byte[] byteData) { StringBuffer sb=new StringBuffer(); for (int i = 0; i < byteData.length; i++) { if (i != 0) sb.append(":"); int b = byteData[i] & 0xff; String hex = Integer.toHexString(b); if (hex.length() == 1) sb.append("0");