Here you can find the source of doSHA1(byte[] buf)
static String doSHA1(byte[] buf)
//package com.java2s; //License from project: Apache License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Formatter; public class Main { static String doSHA1(byte[] buf) { return doSHA1(buf, 0, buf.length); }/* w w w .j a v a2 s .co m*/ static String doSHA1(byte[] buf, int off, int len) { try { MessageDigest md = MessageDigest.getInstance("SHA1"); md.update(buf, off, len); byte[] hv = md.digest(); Formatter f = new Formatter(); for (byte b : hv) { f.format("%02x", b & 0xFF); } return f.toString(); } catch (NoSuchAlgorithmException nsae) { throw new Error(nsae); } } }