Here you can find the source of md5(String string)
Parameter | Description |
---|---|
string | input string |
private static String md5(String string)
//package com.java2s; /**/*w w w. j a va 2 s . c o m*/ * Copyright 2017 Institute of Computing Technology, Chinese Academy of Sciences. * Licensed under the terms of the Apache 2.0 license. * Please see LICENSE file in the project root for terms */ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /** * Use md5 method to encryption * @param string input string */ private static String md5(String string) { MessageDigest md = null; try { md = MessageDigest.getInstance("md5"); md.update(string.getBytes()); byte[] md5Bytes = md.digest(); return bytes2Hex(md5Bytes); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; } /** * Convert byteArray to String * @param byteArray * @return string of input byteArray */ private static String bytes2Hex(byte[] byteArray) { StringBuffer strBuf = new StringBuffer(); for (int i = 0; i < byteArray.length; i++) { if (byteArray[i] >= 0 && byteArray[i] < 16) { strBuf.append("0"); } strBuf.append(Integer.toHexString(byteArray[i] & 0xFF)); } return strBuf.toString(); } }