Here you can find the source of md5(final String str)
Parameter | Description |
---|---|
str | The string to encrypt. |
Parameter | Description |
---|---|
NoSuchAlgorithmException | If the md5 encryptor is not found. |
public static String md5(final String str) throws NoSuchAlgorithmException
//package com.java2s; //License from project: Apache License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**/*w ww . j av a2 s . co m*/ * This function transform a string into its md5 representation. * * @param str * The string to encrypt. * @return The encrypted string. * @throws NoSuchAlgorithmException * If the md5 encryptor is not found. */ public static String md5(final String str) throws NoSuchAlgorithmException { final byte[] hash = MessageDigest.getInstance("MD5").digest(str.getBytes()); final StringBuilder res = new StringBuilder(); for (final byte element : hash) { final String hex = Integer.toHexString(element); if (hex.length() == 1) res.append('0').append(hex.charAt(hex.length() - 1)); else res.append(hex.substring(hex.length() - 2)); } return (res.toString()); } }