SHA1HashCode { public static String calculateSHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException { if (text != null) { MessageDigest md; md = MessageDigest.getInstance("SHA-1"); md.update(text.getBytes("iso-8859-1"), 0, text.length()); byte[] sha1hash = md.digest(); return convertToHex(sha1hash); } else { return ""; } }  static String calculateSHA1(String text);  }
@Test public void testCalculateSHA1() throws Exception { System.out.println("caluclateSHA1"); String sText = "<text></text>"; String sResult = SHA1HashCode.calculateSHA1(sText); assertEquals("941ce1af75a6a3c1d3b614188b70cd7e20da42fd", sResult); sText = ""; sResult = SHA1HashCode.calculateSHA1(sText); assertEquals("da39a3ee5e6b4b0d3255bfef95601890afd80709", sResult); sText = null; sResult = SHA1HashCode.calculateSHA1(sText); assertEquals("", sResult); }