Here you can find the source of SHA1(String str)
public static String SHA1(String str)
//package com.java2s; //License from project: Artistic License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static String SHA1(String str) { return encrypt(str, "SHA1"); }//from w w w .j av a2s .co m public static String encrypt(String str, String enc) { MessageDigest md = null; String result = null; byte[] bt = str.getBytes(); try { md = MessageDigest.getInstance(enc); md.update(bt); result = bytes2Hex(md.digest()); } catch (NoSuchAlgorithmException e) { return null; } return result; } private static String bytes2Hex(byte[] bts) { String des = ""; String tmp = null; for (byte bt : bts) { tmp = (Integer.toHexString(bt & 0xFF)); if (tmp.length() == 1) { des += "0"; } des += tmp; } return des; } }