Here you can find the source of digest(byte[] bytes, String txt)
public final static byte[] digest(byte[] bytes, String txt)
//package com.java2s; /* //from w ww . j ava 2 s.co m * Copyright (C) 2009 by ?yvind Hanssen (ohanssen@acm.org) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ import java.security.*; public class Main { /** * Compute a MD5 hash from the text. Text can be given as * an array of bytes, a string or both. A string will be converted * to bytes using the UTF-8 encoding before computing the hash. */ public final static byte[] digest(byte[] bytes, String txt) { try { MessageDigest dig = MessageDigest.getInstance("MD5"); if (bytes != null) dig.update(bytes); if (txt != null) dig.update(txt.getBytes("UTF-8")); return dig.digest(); } catch (Exception e) { System.out.println("*** Cannot generate message digest: " + e); return null; } } }