Java MD5 Byte Array md5(byte[] data)

Here you can find the source of md5(byte[] data)

Description

md

License

Open Source License

Declaration

public static String md5(byte[] data) 

Method Source Code

//package com.java2s;
/*/*from  w  w w  . j ava 2  s  . c  o m*/
 * gMix open source project - https://svs.informatik.uni-hamburg.de/gmix/
 * Copyright (C) 2012  Karl-Peter Fuchs
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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

public class Main {
    public static String md5(byte[] data) {
        return "[" + asAscii(new String(generateMD5Hash(data))) + "]";
    }

    public static String asAscii(String s) {
        String result = "";
        for (int i = 0; i < s.length(); i++) {
            result += (int) s.charAt(i);// +" ";
        }
        return result;
    }

    public static byte[] generateMD5Hash(byte[] data) {

        try {

            MessageDigest md = MessageDigest.getInstance("MD5");
            return md.digest(data);

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return null;

    }
}

Related

  1. md5(byte[] bytes)
  2. md5(byte[] data)
  3. md5(byte[] data)
  4. md5(byte[] data)
  5. md5(byte[] data)
  6. md5(byte[] input)
  7. md5(byte[] input)
  8. md5(byte[] input)
  9. md5(byte[] input)