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.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static final String ENCRY_MD5 = "md5"; public static final String ENCRY_SHA = "sha-1"; public static String sha1(String input) { return encrypt(input, ENCRY_SHA); }// w ww.j av a2 s . co m public static String encrypt(String input, String... algorithms) { String algorithm = ENCRY_MD5; if (input == null || "".equals(input.trim())) { throw new IllegalArgumentException("Please input the encrypted content !"); } if (algorithms.length > 0) { algorithm = algorithms[0]; } byte[] bytes = null; try { MessageDigest md = MessageDigest.getInstance(algorithm); md.update(input.getBytes("UTF8")); bytes = md.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return byte2hex(bytes); } private static String byte2hex(byte[] bytes) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < bytes.length; ++i) { sb.append(Integer.toHexString((bytes[i] & 0xFF) | 0x100).substring(1, 3)); } return sb.toString(); } }