Here you can find the source of sha1(String input)
public static String sha1(String input)
//package com.java2s; //License from project: Apache License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static String sha1(String input) { MessageDigest mDigest = null; try {/*from ww w . ja v a 2s . c om*/ mDigest = MessageDigest.getInstance("SHA1"); } catch (NoSuchAlgorithmException e) { return "" + input.hashCode(); } byte[] result = mDigest.digest(input.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < result.length; i++) { sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } public static String sha1(byte[] data) { MessageDigest mDigest = null; try { mDigest = MessageDigest.getInstance("SHA1"); } catch (NoSuchAlgorithmException e) { return "" + data.hashCode(); } byte[] result = mDigest.digest(data); StringBuffer sb = new StringBuffer(); for (int i = 0; i < result.length; i++) { sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } }