Here you can find the source of md5(String data)
Parameter | Description |
---|---|
data | data to hash |
Parameter | Description |
---|---|
NoSuchAlgorithmException | an exception |
public static String md5(String data)
//package com.java2s; //License from project: Open Source License import java.security.MessageDigest; public class Main { /**/* ww w . ja v a 2 s . c om*/ * Convert data to md5 * @param data data to hash * @return hashed data * @throws NoSuchAlgorithmException */ public static String md5(String data) { try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(data.getBytes()); return bytesToHex(md.digest()); } catch (Exception ex) { } return ""; } public static String bytesToHex(byte[] bytes) { StringBuffer result = new StringBuffer(); for (byte byt : bytes) result.append(Integer.toString((byt & 0xff) + 0x100, 16).substring(1)); return result.toString(); } }