Java MD5 String md5(final String inData)

Here you can find the source of md5(final String inData)

Description

Create an MD5 hash from the given string.

License

Apache License

Parameter

Parameter Description
inData the data string to be hashed.

Exception

Parameter Description
NoSuchAlgorithmException If the hashing algorithm can not befound.

Return

A hash of the input data string.

Declaration

public static String md5(final String inData) throws NoSuchAlgorithmException 

Method Source Code


//package com.java2s;
/*-/* w  w  w . j  av  a 2 s . c  o m*/
 * #%L
 * Eureka! Clinical User Common
 * %%
 * Copyright (C) 2016 Emory University
 * %%
 * 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.
 * #L%
 */

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    /**
     * Create an MD5 hash from the given string.
     * 
     * @param inData the data string to be hashed.
     * @return A hash of the input data string.
     * @throws NoSuchAlgorithmException If the hashing algorithm can not be
     *             found.
     */
    public static String md5(final String inData) throws NoSuchAlgorithmException {
        StringBuilder hexBuilder = new StringBuilder();
        MessageDigest digest = MessageDigest.getInstance("MD5");
        digest.update(inData.getBytes());
        for (byte b : digest.digest()) {
            hexBuilder.append(Integer.toHexString(b & 0x00FF));
        }
        return hexBuilder.toString();
    }
}

Related

  1. md5(File file)
  2. md5(File gcdZipFile)
  3. md5(final File file)
  4. md5(final InputStream in)
  5. md5(final String data)
  6. md5(final String input)
  7. md5(final String input)
  8. md5(final String message)
  9. md5(final String s)