Here you can find the source of generateSHA1(String message)
public static String generateSHA1(String message)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.security.*; public class Main { public static String generateSHA1(String message) { return hashString(message, "SHA-1"); }/* w w w . j a va 2 s . c o m*/ private static String hashString(String message, String algorithm) { try { MessageDigest digest = MessageDigest.getInstance(algorithm); byte[] hashedBytes = digest.digest(message.getBytes("UTF-8")); return convertByteArrayToHexString(hashedBytes); } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) { return "problem"; } } private static String convertByteArrayToHexString(byte[] arrayBytes) { StringBuffer stringBuffer = new StringBuffer(); for (int i = 0; i < arrayBytes.length; i++) { stringBuffer.append(Integer.toString((arrayBytes[i] & 0xff) + 0x100, 16).substring(1)); } return stringBuffer.toString(); } }