Here you can find the source of md5(java.lang.String message)
Parameter | Description |
---|---|
message | not null |
public static String md5(java.lang.String message)
//package com.java2s; /**************************************************************** * Licensed to the Apache Software Foundation (ASF) under one * * or more contributor license agreements. See the NOTICE file * * distributed with this work for additional information * * regarding copyright ownership. The ASF licenses this file * * to you under the Apache License, Version 2.0 (the * * "License"); you may not use this file except in compliance * * with the License. You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * 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; import java.security.NoSuchAlgorithmException; public class Main { /**/* w w w . j a v a 2 s.c om*/ * Creates an MD5 digest from the message. * Note that this implementation is unsalted. * @param message not null * @return MD5 digest, not null */ public static String md5(java.lang.String message) { try { MessageDigest md = MessageDigest.getInstance("MD5"); StringBuilder sb = new StringBuilder(); byte buf[] = message.getBytes(); byte[] md5 = md.digest(buf); //System.out.println(message); for (byte aMd5 : md5) { String tmpStr = "0" + Integer.toHexString((0xff & aMd5)); sb.append(tmpStr.substring(tmpStr.length() - 2)); } return sb.toString(); } catch (NoSuchAlgorithmException e) { return null; } } }