Here you can find the source of generateHash(final String msg, final String hashAlgorithm)
public static String generateHash(final String msg, final String hashAlgorithm)
//package com.java2s; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static String generateHash(final String msg, final String hashAlgorithm) { if (!hashAlgorithm.equals("plain")) { StringBuffer hexString = new StringBuffer(); try { MessageDigest messageDigest = MessageDigest.getInstance(hashAlgorithm); messageDigest.update(msg.getBytes()); byte[] digest = messageDigest.digest(); for (byte aDigest : digest) { String val = Integer.toHexString(0xFF & aDigest); if (val.length() < 2) { val = "0" + val; }// www . j av a 2 s. c o m hexString.append(val); } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return hexString.toString(); } else { return msg; } } }