Here you can find the source of md5sum(String message)
Parameter | Description |
---|---|
message | string to digested |
public static String md5sum(String message)
//package com.java2s; /*//from w w w .j av a2 s . c om * This file is part of cBioPortal. * * cBioPortal is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.UnsupportedEncodingException; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static final String encodeAlgorithm = "MD5"; public static final String characterEncoding = "UTF-8"; public static final int md5Base = 16; /** * Generates an MD5 sum for the given string. * * @param message string to digested * @return MD5 sum corresponding to the given text */ public static String md5sum(String message) { MessageDigest md5; byte[] md5sumBytes; String sum = null; try { md5 = MessageDigest.getInstance(encodeAlgorithm); md5sumBytes = md5.digest(message.getBytes(characterEncoding)); sum = (new BigInteger(1, md5sumBytes)).toString(md5Base); } catch (NoSuchAlgorithmException e) { sum = null; } catch (UnsupportedEncodingException e) { sum = null; } return sum; } }