Java MD5 Sum md5sum(String input)

Here you can find the source of md5sum(String input)

Description

Return the MD5 checksum of the given string

License

Apache License

Parameter

Parameter Description
input a parameter

Declaration

public static String md5sum(String input) 

Method Source Code

//package com.java2s;
/******************************************************************************
 *  Copyright 2015 by OLTPBenchmark Project                                   *
 *                                                                            *
 *  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 {
    /**/*from  w w w .j  a va 2 s  .  c  o m*/
     * Return the MD5 checksum of the given string
     * @param input
     * @return
     */
    public static String md5sum(String input) {
        MessageDigest digest = null;
        try {
            digest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
            throw new RuntimeException("Unable to compute md5sum for string", ex);
        }
        assert (digest != null);
        digest.update(input.getBytes());
        BigInteger hash = new BigInteger(1, digest.digest());
        return (hash.toString(16));
    }
}

Related

  1. md5sum(File file)
  2. md5sum(File library)
  3. md5sum(InputStream file)
  4. md5sum(InputStream in)
  5. md5sum(String data)
  6. md5sum(String inString)
  7. md5sum(String message)
  8. md5Sum(String msg)
  9. md5sum(String str)