Here you can find the source of sha1Hash(String s)
public static String sha1Hash(String s)
//package com.java2s; //License from project: Apache License import java.nio.charset.Charset; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static final char[] hexArray = "0123456789abcdef".toCharArray(); public static String sha1Hash(String s) { if (s == null) { return null; }//from ww w.j ava2s. com final MessageDigest messageDigest; try { messageDigest = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e); } final byte[] digest = messageDigest.digest(s.getBytes(Charset.forName("UTF-8"))); return bytesToHex(digest); } public static String bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } return new String(hexChars); } }