Here you can find the source of md5(String input)
Parameter | Description |
---|---|
input | - String to hash |
Parameter | Description |
---|---|
NoSuchAlgorithmException | - in case "MD5" isnt a correct input |
public static String md5(String input) throws NoSuchAlgorithmException
//package com.java2s; /*//from w w w . j a v a2 s.c om * This file is part of FTB Launcher. * * Copyright ? 2012-2013, FTB Launcher Contributors <https://github.com/Slowpoke101/FTBLaunch/> * FTB Launcher is 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. */ import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /** * @param input - String to hash * @return - hashed string * @throws NoSuchAlgorithmException - in case "MD5" isnt a correct input */ public static String md5(String input) throws NoSuchAlgorithmException { String result = input; if (input != null) { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(input.getBytes()); BigInteger hash = new BigInteger(1, md.digest()); result = hash.toString(16); while (result.length() < 32) { result = "0" + result; } } return result; } }