public static String getJschFingerprint(byte[] keyBlob) throws Exception { final String[] fingerPrintChars = { "0","1","2","3","4","5","6","7","8","9", "a","b","c","d","e","f" }; HASH hash = new MD5(); hash.init(); hash.update(keyBlob, 0, keyBlob.length); byte[] foo = hash.digest(); StringBuffer sb = new StringBuffer(); int bar; for(int i = 0; i < foo.length; i++){ bar = foo[i]&0xff; sb.append(fingerPrintChars[(bar>>>4)&0xf]); sb.append(fingerPrintChars[(bar)&0xf]); if(i + 1 < foo.length) { sb.append(":"); } } return sb.toString(); }
public static String getFingerPrint(final HASH hash, final byte[] data) { checkNotNull(hash); checkNotNull(data); try { hash.init(); hash.update(data, 0, data.length); byte[] digest = hash.digest(); StringBuffer sb = new StringBuffer(); int offset; for (int i = 0; i < digest.length; i++) { offset = digest[i] & 0xff; sb.append(CHARS[(offset >>> 4) & 0xf]); sb.append(CHARS[(offset) & 0xf]); if (i + 1 < digest.length) { sb.append(":"); } } return sb.toString(); } catch (Exception exception) { return "???"; } }
public static HASH md5() { return new com.jcraft.jsch.jce.MD5(); }