Here you can find the source of sha1(String s)
public static String sha1(String s)
//package com.java2s; //License from project: Apache License import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { static final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); public static String sha1(String s) { MessageDigest md = getMessageDigest("sha-1"); return bytes2HexString(md.digest(s.getBytes(StandardCharsets.UTF_8))); }/* w ww .java 2 s .co m*/ static MessageDigest getMessageDigest(String name) { try { return MessageDigest.getInstance(name); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } } static String bytes2HexString(byte[] b) { StringBuilder sb = new StringBuilder(b.length << 2); for (byte x : b) { int hi = (x & 0xf0) >> 4; int lo = x & 0x0f; sb.append(HEX_CHARS[hi]); sb.append(HEX_CHARS[lo]); } return sb.toString(); } }