Here you can find the source of md5(String text)
public static String md5(String text)
//package com.java2s; /**/*from w w w . j a v a 2 s .c om*/ * Copyright (c) 2011, StringUtil.java TAIHEIOT and/or its affiliates. All rights reserved. * * Licensed under the TAIHEIOT License, Version 1.0 (the "License"); * you may not use this file except in compliance with the License. * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.security.MessageDigest; public class Main { public static String md5(String text) { if (isNullOrEmpty(text)) return ""; StringBuffer hexString = new StringBuffer(); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(text.getBytes()); byte[] digest = md.digest(); for (int i = 0; i < digest.length; i++) { text = Integer.toHexString(0xFF & digest[i]); if (text.length() < 2) { text = "0" + text; } hexString.append(text); } } catch (Exception e) { e.printStackTrace(); } return hexString.toString(); } public static boolean isNullOrEmpty(String string) { if (string == null) return true; else if (string.trim().isEmpty()) return true; return false; } }