Here you can find the source of SHA1(MessageDigest messageDigest, String... texts)
public static String SHA1(MessageDigest messageDigest, String... texts) throws Exception
//package com.java2s; //License from project: Apache License import java.security.MessageDigest; public class Main { private static final char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; public static String SHA1(MessageDigest messageDigest, String... texts) throws Exception { try {/* w w w. j a v a 2s . co m*/ if (messageDigest == null) { throw new Exception("messageDigest is null or text is null"); } if (texts == null || texts.length == 0) return null; if (texts[0] == null) return null; messageDigest.reset(); for (String tt : texts) { if (tt != null) messageDigest.update(tt.getBytes()); } byte[] updateBytes = messageDigest.digest(); int len = updateBytes.length; char myChar[] = new char[len * 2]; int k = 0; for (int i = 0; i < len; i++) { byte byte0 = updateBytes[i]; myChar[k++] = hexDigits[byte0 >>> 4 & 0x0f]; myChar[k++] = hexDigits[byte0 & 0x0f]; } return new String(myChar); } catch (Exception e) { throw e; } } public static String SHA1(String... texts) throws Exception { try { if (texts == null || texts.length == 0) return null; if (texts[0] == null) return null; MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); for (String tt : texts) { if (tt != null) messageDigest.update(tt.getBytes()); } byte[] updateBytes = messageDigest.digest(); int len = updateBytes.length; char myChar[] = new char[len * 2]; int k = 0; for (int i = 0; i < len; i++) { byte byte0 = updateBytes[i]; myChar[k++] = hexDigits[byte0 >>> 4 & 0x0f]; myChar[k++] = hexDigits[byte0 & 0x0f]; } return new String(myChar); } catch (Exception e) { throw e; } } }