@Override public String toString() { return asString(); }
private String toHexString(byte[] b) { String str = new BigInteger(1, b).toString(16); while (str.length() < hexStringLength()) { str = "0" + str; } return str; }
/** * @return hash as hex string */ public String asString() { return toHexString(asBytes()); }
public void asBytes(byte[] bytes) { asBytes(bytes, 0); }
public Hash update(byte[] b) { return update(b, 0, b.length); }
public Hash(String name) { hash = init(name); }
@Test public void sha1_test() { String data = "foo bar\n"; Assert.assertEquals("d53a205a336e07cf9eac45471b3870f9489288ec", SHA1.create().update(data).asString()); byte[] hash = new byte[20]; SHA1.create().update(data).asBytes(hash); Assert.assertArrayEquals(SHA1.create().update(data).asBytes(), hash); }
public void asBytes(byte[] bytes) { asBytes(bytes, 0); }
/** * @return hash as hex string */ public String asString() { return toHexString(asBytes()); }
public Hash update(byte[] b) { return update(b, 0, b.length); }
public Hash(String name) { hash = init(name); }
@Override public String toString() { return asString(); }
public static byte[] toTransfer(SecretKey key) { byte[] b = new byte[32]; System.arraycopy(key.getEncoded(), 0, b, 0, 16); System.arraycopy(MD5.create().update(key.getEncoded()).asBytes(), 0, b, 16, 16); return b; }
/** * update hash with getBytes(UTF8) */ public Hash update(String s) { return update(s.getBytes(UTF8)); }
private String toHexString(byte[] b) { String str = new BigInteger(1, b).toString(16); while (str.length() < hexStringLength()) { str = "0" + str; } return str; }