/** * Get the hexadecimal representation of a byte array. * * @param array * * @return hex string */ public static String toHex(byte[] array) { return toHex(array, 0, array.length); }
/** * Computes the fingerprint for a public key, in the standard SSH format, e.g. "4b:69:6c:72:6f:79:20:77:61:73:20:68:65:72:65:21" * * @param key the public key * @return the fingerprint * @see <a href="http://tools.ietf.org/html/draft-friedl-secsh-fingerprint-00">specification</a> */ public static String getFingerprint(PublicKey key) { MessageDigest md5; try { md5 = getMessageDigest("MD5"); } catch (GeneralSecurityException e) { throw new SSHRuntimeException(e); } md5.update(new Buffer.PlainBuffer().putPublicKey(key).getCompactData()); final String undelimited = ByteArrayUtils.toHex(md5.digest()); assert undelimited.length() == 32 : "md5 contract"; StringBuilder fp = new StringBuilder(undelimited.substring(0, 2)); for (int i = 2; i <= undelimited.length() - 2; i += 2) fp.append(":").append(undelimited.substring(i, i + 2)); return fp.toString(); }
/** * Get the hexadecimal representation of a byte array. * * @param array * * @return hex string */ public static String toHex(byte[] array) { return toHex(array, 0, array.length); }
/** * Get the hexadecimal representation of a byte array. * * @param array * * @return hex string */ public static String toHex(byte[] array) { return toHex(array, 0, array.length); }
/** * Computes the fingerprint for a public key, in the standard SSH format, e.g. "4b:69:6c:72:6f:79:20:77:61:73:20:68:65:72:65:21" * * @param key the public key * @return the fingerprint * @see <a href="http://tools.ietf.org/html/draft-friedl-secsh-fingerprint-00">specification</a> */ public static String getFingerprint(PublicKey key) { MessageDigest md5; try { md5 = getMessageDigest("MD5"); } catch (GeneralSecurityException e) { throw new SSHRuntimeException(e); } md5.update(new Buffer.PlainBuffer().putPublicKey(key).getCompactData()); final String undelimited = ByteArrayUtils.toHex(md5.digest()); assert undelimited.length() == 32 : "md5 contract"; StringBuilder fp = new StringBuilder(undelimited.substring(0, 2)); for (int i = 2; i <= undelimited.length() - 2; i += 2) fp.append(":").append(undelimited.substring(i, i + 2)); return fp.toString(); }
/** * Computes the fingerprint for a public key, in the standard SSH format, e.g. "4b:69:6c:72:6f:79:20:77:61:73:20:68:65:72:65:21" * * @param key the public key * * @return the fingerprint * * @see <a href="http://tools.ietf.org/html/draft-friedl-secsh-fingerprint-00">specification</a> */ public static String getFingerprint(PublicKey key) { MessageDigest md5; try { md5 = getMessageDigest("MD5"); } catch (GeneralSecurityException e) { throw new SSHRuntimeException(e); } md5.update(new Buffer.PlainBuffer().putPublicKey(key).getCompactData()); final String undelimited = ByteArrayUtils.toHex(md5.digest()); assert undelimited.length() == 32 : "md5 contract"; StringBuilder fp = new StringBuilder(undelimited.substring(0, 2)); for (int i = 2; i <= undelimited.length() - 2; i += 2) fp.append(":").append(undelimited.substring(i, i + 2)); return fp.toString(); }