Here you can find the source of md5(String target)
Parameter | Description |
---|---|
target | a parameter |
Parameter | Description |
---|---|
NoSuchAlgorithmException | an exception |
public static String md5(String target) throws NoSuchAlgorithmException, UnsupportedEncodingException
//package com.java2s; import java.io.*; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**/* ww w . j av a 2s. c o m*/ * MD5 * * @param target * @return String * @throws NoSuchAlgorithmException */ public static String md5(String target) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(target.getBytes("utf-8")); byte[] md5Bytes = digest.digest(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < md5Bytes.length; i++) { sb.append(Character.forDigit(md5Bytes[i] >>> 4 & 0xf, 16)); sb.append(Character.forDigit(md5Bytes[i] & 0xf, 16)); } return sb.toString(); } public static byte[] md5(byte[] src) throws NoSuchAlgorithmException { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(src); byte[] result = digest.digest(); return result; } }