Here you can find the source of md5(final String s)
Parameter | Description |
---|---|
s | The String to be hashed |
final static String md5(final String s)
//package com.java2s; /*//from w w w. ja v a 2 s .co m * Licensed 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. * * See the NOTICE file distributed with this work for additional * information regarding copyright ownership. */ import java.math.BigInteger; import java.security.MessageDigest; public class Main { /** * Fast and dirty MD5 hasher. Please note that this logic does not always work properly * * @param s The String to be hashed * @return Hashed value of the String */ final static String md5(final String s) { if (s == null) { throw new NullPointerException(); } if (s.length() == 0) { return ""; } try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(s.getBytes()); BigInteger hash = new BigInteger(1, md5.digest()); return hash.toString(16); } catch (Exception e) { throw new RuntimeException(e); } } }